# Built-in Functions → sum

Aggregation function that returns the sum of the values for each group.

## Signature

sum(double[] exp, groupBy)

The following table illustrates the function parameters:

ParameterDescription
double[] expexpression evaluating to double
groupByGrouping function that specifies which group of data to operate over

## Returns

double representing the sum of values for each group.

## Example

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 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:

Note

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 Manage Dataset (+).
• In the Manage Data Sets panel, select Sales_Acme.
• From the Data panel, drag and drop the following fields to the Grouping Dimension tray:
• Year
• Quarter
• Month
• 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.
• Double-click 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.
sum(Sales_Acme.Sales.Amount_Sold,groupBy(Sales_Acme.Sales.Year,Sales_Acme.Sales.Quarter))
• 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.