The Group-By function selects records from a data-source that generates distinct values for a specified field.
The following sample lists the department history count for each employee.
Note:
• | Only one data source is used (sql-data-source which joins the emp and hist tables). |
Distinct employee IDs are generated using group-by. Afterwards, the department count is computed using a filter function that filters the initial data source according to the current employee ID.
Note.
• | The above example is part of the GroupBySample.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:employee name="Arthur Clark" department-count="1"/>
<ns:employee name="John Brown" department-count="4"/>
<ns:employee name="Mary Jane" department-count="3"/>
</ns:root>