Aggregate Functions

Top Previous Topic Next Topic  Print this topic

Aggregate Functions are functions that compute values over all records in a data source.

 

The following aggregate functions are supported:

count - Returns the number of records in a data set.
max - Iterates over the specified data source and computes the maximum value of the referenced source.
min - Similar to max except it computes the minimum value.
average - Similar to max except it computes average value from the specified source.
sum - Similar as max except it computes sum from the specified source.
single-result-function - returns a record from the data source. It can return the first, last, or a certain record, the latest specified by the "index" parameter.

 

The sample below uses the Hist table to present all the supported aggregate functions. It returns the record count, the number of hours worked by the employee with ID = 1, the maximum, minimum, average and sum of hours worked.

 

Aggregate-Functions

 

Note:

The above example is part of the AggregateFunctions.dax document, located in the Samples/Job Samples folder.

 

Output:

 

 

       <?xml version="1.0" encoding="UTF-8" standalone="yes"?>

       <ns:root xmlns:ns="http://www.tempuri.org/XML">

               <ns:count>7</ns:count>

               <ns:max-hours-worked>8000</ns:max-hours-worked>

               <ns:min-hours-worked>100</ns:min-hours-worked>

               <ns:average-hours-worked>2557</ns:average-hours-worked>

               <ns:sum-hours-worked>17900</ns:sum-hours-worked>

               <ns:hours-worked-for-employee-with-id-1>300</ns:hours-worked-for-employee-with-id-1>

       </ns:root>