Skip to content

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.

An Excel table with a Date column and one column per document type: Passport Copy, NI Number, Signed Contract, Medical Form, P45, Driving License and Address Proof. Each cell holds a seven-digit employee number, and some cells are shaded red.

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.

  • Load the table into Power Query. In the Power Query Editor it looks like this:

The log in the Power Query Editor, with the formula bar showing Excel.CurrentWorkbook as the source. Empty cells now show as null.

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

The same table after Table.RemoveColumns has removed the Date column, so the first column is Passport Copy.

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

The unpivoted table, made by Table.UnpivotOtherColumns, with an Attribute column of document types and a Value column of employee numbers.

  • 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:

A single EmpNo column listing twelve distinct employee numbers.

  • 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:

A single DocsList column listing the seven document types, from Passport Copy to Address Proof.

  • 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:

A DocsList column and an EmpNo column, where Passport Copy is repeated against each of the twelve employee numbers, followed by NI Number against the same numbers.

  • 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.

The Merge dialog with MultipleCombo above and DocsSubmitted below, the matching columns numbered 1 and 2 on each side, and Join Kind set to Left Anti (rows only in first).

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 outstanding documents, with EmpNo sorted in descending order and the missing document type beside each number in DocsList.

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:

Seven employee numbers, each with a Docs In One Line cell such as Passport Copy; NI Number; Driving License.

  • 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:

An error-checking sheet whose table lists each duplicated employee number, the column it was duplicated in, and how many times it appears.

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