HR - On-boarding
Imagine you work in an HR team, and part of your job during on-boarding is to check that every new starter has sent in every form they owe.
The forms take time to complete, so they do not arrive together. One person might email two or three of them, and then post two or three more a few days later.
To keep track, you log each form as it arrives in an Excel table like the one below. Each column is a type of document, and each row records the employee numbers whose copy of that document arrived on a given date.

The red cells are duplicates, which conditional formatting has highlighted. They appear because the same employee number was sometimes entered more than once in the same column by mistake.
Once most of the forms are in, you need a quick way to see which documents are still outstanding for each person, so that your team knows whom to chase. This page shows how to build that list with Power Query.
1. Load and unpivot the log
Section titled “1. Load and unpivot the log”- Load the table into Power Query. In the Power Query Editor it looks like this:

- Remove the Date column, because it is not needed for this check.

- Unpivot the document columns, so that the table has just two columns: the document type in Attribute and the employee number in Value.

- Name the query DocsSubmitted.
Unpivoting also drops the empty cells, so each row of DocsSubmitted records one document received from one employee.
2. Make lists of the employees and the document types
Section titled “2. Make lists of the employees and the document types”- Create a new query that lists each employee who has sent at least one document. It starts from DocsSubmitted, removes the Attribute column, renames Value to EmpNo and removes duplicates. The M code is:
let Source = DocsSubmitted, #"Removed Columns" = Table.RemoveColumns(Source,{"Attribute"}), #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Value", "EmpNo"}}), #"Removed Duplicates" = Table.Distinct(#"Renamed Columns")in #"Removed Duplicates"The result is a single column of employee numbers, each appearing once:

-
Name the query UniqEmpNo.
-
Build a second query in the same way to list each document type once, with this M code:
let Source = DocsSubmitted, #"Removed Columns" = Table.RemoveColumns(Source,{"Value"}), #"Removed Duplicates" = Table.Distinct(#"Removed Columns"), #"Renamed Columns" = Table.RenameColumns(#"Removed Duplicates",{{"Attribute", "DocsList"}})in #"Renamed Columns"Its result is the list of document types:

- Name the query UniqDocsList.
3. Pair every employee with every document
Section titled “3. Pair every employee with every document”The next query builds a Cartesian product of the two lists, which is every possible pairing of an employee with a document type. Together these pairings are the full set of documents you expect to receive.
- It starts from UniqDocsList, adds a custom column that holds the whole UniqEmpNo table on every row, and then expands that column. The M code is:
let Source = UniqDocsList, #"Added Custom" = Table.AddColumn(Source, "Custom", each UniqEmpNo), #"Expanded Custom" = Table.ExpandTableColumn(#"Added Custom", "Custom", {"EmpNo"}, {"EmpNo"})in #"Expanded Custom"Each document type now appears once for every employee:

- Name the query MultipleCombo.
4. List the missing documents, one per row
Section titled “4. List the missing documents, one per row”- Start a new query with Merge Queries, choosing MultipleCombo as the first table and DocsSubmitted as the second. Match EmpNo to Value and DocsList to Attribute, selecting the columns in that order on each side, and set the join kind to Left Anti.

A left anti join keeps only the rows of the first table that have no match in the second. Here that means the expected documents that have not been received.
- Remove the merged column, put EmpNo first and sort by employee number, so the result looks like this:

The finished M code is:
let Source = Table.NestedJoin(MultipleCombo, {"EmpNo", "DocsList"}, DocsSubmitted, {"Value", "Attribute"}, "DocsSubmitted", JoinKind.LeftAnti), #"Expanded DocsSubmitted" = Table.ExpandTableColumn(Source, "DocsSubmitted", {"Attribute", "Value"}, {"Attribute", "Value"}), #"Removed Columns" = Table.RemoveColumns(#"Expanded DocsSubmitted",{"Attribute", "Value"}), #"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"EmpNo", "DocsList"}), #"Sorted Rows" = Table.Sort(#"Reordered Columns",{{"EmpNo", Order.Descending}})in #"Sorted Rows"- Name the query DocsNotSubmitted.
5. List the missing documents, one row per employee
Section titled “5. List the missing documents, one row per employee”- Create a reference to DocsNotSubmitted and apply this M code:
let Source = DocsNotSubmitted, #"Grouped Rows" = Table.Group(Source, {"EmpNo"}, {{"Docs In One Line", each Text.Combine([DocsList], "; "), type text}})in #"Grouped Rows"The query groups the rows by employee, and Text.Combine joins each employee’s missing documents into one cell, separated by semicolons. This is the version to hand to whoever does the chasing:

6. Check for duplicate entries
Section titled “6. Check for duplicate entries”- Create a new query that references DocsSubmitted, and apply this M code:
let Source = DocsSubmitted, #"Grouped Rows" = Table.Group(Source, {"Value", "Attribute"}, {{"Count", each Table.RowCount(_), type number}}), #"Sorted Rows1" = Table.Sort(#"Grouped Rows",{{"Value", Order.Descending}}), #"Filtered Rows" = Table.SelectRows(#"Sorted Rows1", each ([Count] <> 1)), #"Renamed Columns" = Table.RenameColumns(#"Filtered Rows",{{"Value", "EmpNo"}, {"Attribute", "Duplicated in Which Column?"}, {"Count", "How Many Times?"}})in #"Renamed Columns"The query groups the rows by employee number and document type, counts each group, and keeps only the groups whose count is more than one. Those groups are the duplicate entries.
Loaded to a worksheet, the result looks like this:

Refreshing the queries after each new batch of forms updates both the list of outstanding documents and the duplicate check.