Aggregate Data within a Form
Dynamic Matrix supports different data aggregation methods that you can use to combine or summarize data across multiple matrix rows or columns based on provided answers. For instance, in a Dynamic Matrix where users input numerical values, aggregation might involve calculating totals, averages, counts, or other statistical operations across rows or columns. This example illustrates the dynamic generation of Totals for rows and columns based on selected phone models and their quantities.
Calculate Row Totals
A row total aggregates values in a particular matrix row. To calculate and display row totals, create a column with the cellType
property set to "expression"
. Create an expression to calculate row totals. Within the expression, you can access individual row cells using the row
prefix as follows: {row.columnName}
. For a code example, refer to the "Total" column configuration in the survey.json
file.
Calculate Column Totals
A column total aggregates values in an individual matrix column. Use the following column properties to configure column totals:
totalType
:"sum"
|"count"
|"min"
|"max"
|"avg"
An aggregation method.totalDisplayStyle
:"decimal"
|"currency"
|"percent"
A format for calculated total values.totalFormat
:string
A string pattern used to display column totals. To reference a total value within this pattern, use the{0}
placeholder.
This demo calculates column totals for the "Phone model", "Quantity", and "Total" columns. You can find their configurations in the survey.json
file.
To access the total value of an individual column, use the total
suffix as follows: {matrixName-columnName.total}
. In the current demo, this suffix is used by the "VAT" and "Total" questions. Refer to the survey.json
file for a code example.