Skip to main content
Functions can contain functions, so it’s possible to pass the result of one aggregate function to another aggregate function for compound operations. For example, with regards to a sale amount, first weigh the amount and then converted to a specific currency using: CurrencyConvert(Weighted(amount;probPercent);currencyId))

Scenario 1

To demonstrate the concept, construct a query that displays the top sales representatives this month. Do this by specifying a restriction where the userGroup equals the sales group, the saleStatus is sold, and the sale date is within the past month. Sort the results by the sum of the sale amount, descending. Then add the following aggregate functions to display the results in a footer - one for each distinct group:
  • using Sum and ConvertCurrency, convert all sale amounts to one currency and then sum the amounts.
  • use GroupBy to divide the results by full name, personId, and title.
The CultureDataFormatter method is used to format the summed amount into local currency in both the footer and grandtotal rows.

Query results

Scenario 2

Another common scenario to demonstrate nested functions is to group sales based on a DatePart. Combined with a GroupBy, the use of DatePart makes it easy to aggregate sales by week, month, or quarter. Use the previous example as a template and modify the restriction sale date to show just this year. Modify the Sort to use the GroupBy DatePart, ascending. Then change the desired columns to just include the Sum of sale amounts and a GroupBy to divide the results by months.