Grouping Tables (to show duplicates)
This page shows how to group a table to count the duplicates of one field, and then carry a value from the grouped rows back onto every row.
Counting duplicates and finding joining dates
Section titled “Counting duplicates and finding joining dates”The example is a list of employee records. Each row holds an employee’s code, name and position, with the start and end dates of that position, so an employee who has held two positions appears twice.

There are two things to add:
- a count of the rows for each employee, which shows who is duplicated
- each employee’s joining date, which is their earliest start date, in a column of its own
1. Summarise the table with Group By
Section titled “1. Summarise the table with Group By”- Load the table into Power Query.
- Select the Employee Code column, and click Group By on the Home tab.
- In the dialog, keep the Count output with the Count Rows operation.
- Click Add aggregation, name the new output Details, and choose the All Rows operation.

Click OK. The table now has one row per employee, with a Table object in each Details cell.

2. Add a custom column
Section titled “2. Add a custom column”On the Add Column tab, click Custom Column. This formula takes the row with the earliest Start Date from each employee’s table:
![The Custom Column dialog creating a column called Custom with the formula Table.Min([Details], “Start Date”)](/_astro/grouping-tables-duplicates-4.Clf5UbLc_Z1YhDkB.webp)
Each cell of the new column holds a Record object, which is that employee’s earliest row.

3. Expand the Custom column
Section titled “3. Expand the Custom column”- Click the expand icon on the Custom column and take only the Start Date field from each record.
- Rename the resulting column to Joining Date.

4. Expand the Details column
Section titled “4. Expand the Details column”Click the expand icon on the Details column, and select every field except Employee Code, because the query already has that column.

Reorder the columns, and the table is back to one row per record with two new columns. Count shows how many rows each employee code has, and Joining Date shows the date each employee first started.

With the joining date on every row, measures such as each employee’s total length of service can now be worked out correctly.