Aggregation function that returns the sum of the values in a column.
sum(double exp, groupBy)
- double exp : expression evaluating to
groupBy: optional grouping function
doublerepresenting the sum of the values in the column. If
sumreturns the sum for each group.
Consider the following table of example data:
Year Quarter Month Amount Sold 2019 Q1 M1 100 2019 Q1 M2 200 2019 Q1 M3 100 2019 Q2 M4 150 2019 Q2 M5 250 2019 Q2 M6 150 2019 Q3 M7 200 2019 Q3 M8 250 2019 Q3 M9 300 2019 Q4 M10 100 2019 Q4 M11 50 2019 Q4 M12 50 2020 Q1 M1 150 2020 Q1 M2 100 2020 Q1 M3 200 2020 Q2 M4 150 2020 Q2 M5 100 2020 Q2 M6 150 2020 Q3 M7 50 2020 Q3 M8 100 2020 Q3 M9 200 2020 Q4 M10 150 2020 Q4 M11 100 2020 Q4 M12 50
Find the total amount sold (add up the values in the Amount Sold column).
Find the total amount sold for each quarter for each year.
SUM(Amount Sold, group by (Year, Quarter))
Use the following steps for detailed instructions on how to use the groupBy parameter:
The data has been uploaded, then added and loaded into a Schema named Sales_Acme. For information on creating a data source and a schema, refer to the Guides→Start document.
- In the Navigation bar, select the Content tab, and then select + New → Add Dashboard.
- In the Add Dashboard dialog, for Name, enter Sales Dashboard, and then select Add.
- In the Action bar, select + (add icon).
- In the Insight panel, select Listing Table or V.
- In Tables, select Aggregated Table.
- In the Data panel, select Add Data Set (+).
- In the Manage Data Sets panel, select Sales_Acme.
From the Data panel, drag and drop the following fields to the Grouping Dimension tray:
- Drag and drop the Amount Sold column to the Measure tray.
- From the Data panel, drag and drop Add Formula to the Measure tray.
The Formula Builder automatically opens:
- In Search Functions, select the down arrow, and then select Aggregation Functions.
sum(double exp, groupBy)to add the formula to the editor.
In the Formula Editor, replace double exp with Amount_Sold and dimension, … with Year,Quarter from the Data panel.
- Select Validate & Save.
- In the Measure tray, double-click the New Formula pill and rename it to Amount Sold Per Quarter.
- In the Action bar, select Save.
For more information, refer to the Level Based Measure document.