Distinct customers
This page counts how many different customers bought something on each day. A plain count of rows per day would overstate the number, because some customers made more than one purchase on the same day, so the duplicates are removed first.
The example starts from this Excel table of sales, which has one row per transaction.

1. Query the table
Section titled “1. Query the table”- Click inside the table, and on Excel’s Data tab click From Table/Range. The Power Query Editor opens with a new query.
- Select the Date column, and set its data type to Date from the Data Type list.
2. Remove duplicate combinations of date and customer
Section titled “2. Remove duplicate combinations of date and customer”- Hold down Shift or Ctrl, and click the Date and Customer column headers to select both.
- Click Remove Duplicates, either on the Home tab or by right-clicking one of the selected headers, as below.

Power Query keeps the first row for each combination of date and customer, and removes the rest. The table now has 9 rows instead of 14.

3. Count the rows for each date
Section titled “3. Count the rows for each date”Each row now stands for one customer on one date, so counting the rows for a date gives the number of distinct customers on that date.
- Select the Date column, and on the Home tab click Group By.
- Check that Date is the column to group by, type DistinctCustomers as the new column name, leave the operation as Count Rows, and click OK.

The query now has one row per date, with the number of distinct customers beside it.
- Click Close & Load to load the result to a table on a new worksheet.

4. The M code
Section titled “4. The M code”let //Load data from the Excel worksheet Source = Excel.CurrentWorkbook(){[Name="Customers"]}[Content], //Set the data type of the Date column to date #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Customer", type text}, {"Sales", Int64.Type}}), //Remove all duplicate combinations of Date and Customer #"Removed Duplicates" = Table.Distinct(#"Changed Type", {"Date", "Customer"}), //Find the count of rows per date #"Grouped Rows" = Table.Group(#"Removed Duplicates", {"Date"}, {{"DistinctCustomers", each Table.RowCount(_), Int64.Type}})in #"Grouped Rows"This example follows one in Chris Webb’s Power Query for Power BI and Excel (Apress).