Group-By function selects records from a data-source that generate distinct values for a specified field.
The following sample lists the department history count for each employee. Note that only one data source is used (sql-data-source which joins the emp and hist tables).
Distinct employee IDs are generated using group-by. After that, the department count is computed using a filter function that filters the initial data source according to the current employee ID.

Note. This sample can be found in GroupBySample.dax in 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>