Skip to content

HR - Inventory Utilisation

This page builds the data behind an inventory utilisation measure for staff. Here the inventory is people’s time, and utilisation is the share of the hours an employee was available that they actually booked to work. The calculation draws on three sources: employee availability records from an HR system, a list of public holidays, and timesheets.

A utilisation figure like this shows how fully staff are being used across a business, and where people are over- or under-loaded.

The first source is an availability table exported from the HR system.

Availability table with one row per employee and period, showing user ID, name, start and end dates, country, department, full- or part-time status, the weekdays worked and hours per day

Each row records how one employee was available over a period. Because an employee’s circumstances change over time, this is a slowly changing dimension: a new row starts whenever the employee’s country, department, full- or part-time status, preferred working days or hours per day change. The latest row for each employee has no end date, because that arrangement is still current.

This assumes the HR system keeps that history, which not every system does.

The second source lists the public holidays for each country, either exported from the HR system or typed in by hand.

Public holidays table listing dates, holiday names, country and day of the week for UK and UAE holidays in 2020

The third source is the timesheet data, which records the hours each employee booked against each day. The example uses three areas of work, but timesheets can be as detailed as the business needs. Where the system supports them, extra fields such as project codes, internal codes or status codes can sit alongside Area of Work.

Timesheet table with user ID, name and area of work down the side, and one column of hours per date across the top

Working out utilisation accurately takes more steps than the small amount of data suggests. The method on this page runs to about 140 transformations, spread across these queries:

  • Set Dates lists every date in the timesheets.
  • Min_Date and Max_Date find the first and last dates to report on.
  • Availability - Day Shortfall Check expands the availability records into days and works out, week by week, how many preferred days each part-time employee lost to holidays.
  • fnRunningTotal is a function that adds a running total column to a table.
  • Availability - Daily works out each employee’s available hours for every day, moving lost days onto other days in the same week.
  • Availability - Weekly totals the daily availability by week.
  • The timesheet query turns the timesheets into hours worked per week and sets them beside the available hours.

The rest of the page builds each query in turn and explains the reasoning, so that the method can be adapted rather than copied.

The first query produces a clean list of the dates that appear in the timesheets.

  • Load the timesheet data into Power Query. It arrives with generic column names and the real headings in the first row.

Timesheet data in the Power Query editor, with columns named Column1 to Column6 and the headings User ID, First Name, Last Name and Area of Work in the first row

  • Filter out the rows where Column3 is blank, which removes the empty rows above the table.
  • Remove Column1 to Column5, because only the date columns are needed here.
  • Promote the first row to headers, so that each column is named after its date.

Date columns after promoting headers, each headed with a date and time and holding nulls

  • Unpivot all the columns. Every date heading becomes a row in an Attribute column, with the hours in a Value column.

Unpivoted data with an Attribute column of dates and times and a Value column of hours

  • Remove the Value column, which this query does not need.
  • Keep only the rows whose Attribute contains a slash, so that anything that is not a date is dropped:
= Table.SelectRows(#"Removed Columns1", each Text.Contains([Attribute], "/"))
  • Change the column’s type to Date/Time.
  • Rename the column to Date.

A single Date column holding dates with times

  • Change the type again, this time to Date, which drops the time.
  • Remove duplicates, in case any date appears twice.
  • Add a Start of Week (Mon) column, which gives the Monday of each date’s week:
= Table.AddColumn(#"Removed Duplicates", "Start of Week (Mon)", each Date.StartOfWeek([Date], Day.Monday), type date)

Date column beside a Start of Week (Mon) column giving the Monday of each date’s week

  • Name the query Set Dates.

The finished query looks like this in the Advanced Editor:

let
Source = Excel.CurrentWorkbook(),
Inventory_Use = Source{[Name="Inventory_Use"]}[Content],
#"Filtered Rows" = Table.SelectRows(Inventory_Use, each ([Column3] <> null)),
#"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Column1", "Column2", "Column3", "Column4", "Column5"}),
#"Promoted Headers" = Table.PromoteHeaders(#"Removed Columns", [PromoteAllScalars=true]),
#"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Promoted Headers", {}, "Attribute", "Value"),
#"Removed Columns1" = Table.RemoveColumns(#"Unpivoted Columns",{"Value"}),
#"Filtered Rows1" = Table.SelectRows(#"Removed Columns1", each Text.Contains([Attribute], "/")),
#"Changed Type" = Table.TransformColumnTypes(#"Filtered Rows1",{{"Attribute", type datetime}}),
#"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"Attribute", "Date"}}),
#"Changed Type1" = Table.TransformColumnTypes(#"Renamed Columns",{{"Date", type date}}),
#"Removed Duplicates" = Table.Distinct(#"Changed Type1"),
#"Inserted Start of Week (Mon)" = Table.AddColumn(#"Removed Duplicates", "Start of Week (Mon)", each Date.StartOfWeek([Date], Day.Monday), type date)
in
#"Inserted Start of Week (Mon)"

The Min_Date query returns the earliest week start in the timesheets, which becomes the first date the report covers.

  • Create a new query, Min_Date, that references Set Dates.
  • Add a custom step that takes the smallest value in Start of Week (Mon):
= List.Min(Source[#"Start of Week (Mon)"])

The query returns a single date.

Formula bar showing List.Min over the Start of Week (Mon) column, with the result 06/04/2020 below it

The Max_Date query returns the last day of the last week in the timesheets.

  • Create a new query, Max_Date, that also references Set Dates.
  • Add a custom step that takes the latest week start and adds six days, so that the result is the Sunday at the end of that week:
= Date.AddDays(List.Max(Source[#"Start of Week (Mon)"]), 6)

This query also returns a single date.

Formula bar showing Date.AddDays applied to the List.Max of Start of Week (Mon), with the result 12/07/2020 below it

Step 4: expand availability into days for the shortfall check

Section titled “Step 4: expand availability into days for the shortfall check”

The next query, Availability - Day Shortfall Check, turns each availability record into one row per day. It then works out, for each week, whether a part-time employee lost any of their preferred days to a holiday. This first part builds the rows of dates.

  • In a new query, load the availability data.

Availability data in the Power Query editor, with some End Date cells null

  • Replace the nulls in End Date with Max_Date, so that every current record runs to the end of the reporting period.

Formula bar showing Table.ReplaceValue putting Max_Date into the End Date column, and the null end dates now reading 12/07/2020

  • In the Mon column, replace Yes with Monday.

Formula bar replacing Yes with Monday in the Mon column, and the Mon column now showing Monday where it said Yes

  • Do the same for each of the other day columns, replacing Yes with the day’s full name.

Day columns from Mon to Sat after the replacements, each holding the full day name or null

  • Merge the seven day columns into one column called Merged Days, with the names separated by commas:
= Table.CombineColumns(Sunday,{"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"},Combiner.CombineTextByDelimiter(", ", QuoteStyle.None),"Merged Days")

Merged Days column listing each record’s preferred days, with empty positions left as commas

  • Add a custom column called Working Days. Full-time employees have no preferred days marked, so this column fills in their standard working week, which runs Monday to Friday everywhere except the UAE, where it includes Sunday instead of Friday. For part-time employees it takes the value of Merged Days.

Custom Column dialog for Working Days, with an if expression that returns the standard working week for full-time employees and Merged Days otherwise

Working Days column beside Merged Days, with the full-time record now listing Monday to Thursday and Sunday

  • Remove Merged Days, because Working Days replaces it.
  • Add a Start of Week column, which gives the first day of the week containing Start Date. The week starts on Sunday in the UAE and on Monday elsewhere.

Custom Column dialog for Start of Week, using Date.StartOfWeek on Start Date with Day.Sunday for the UAE and Day.Monday otherwise

  • Add an End of Week column in the same way, which gives the last day of the week containing End Date.

Custom Column dialog for End of Week, using Date.EndOfWeek on End Date with the same country rule

  • Add a custom column called Dates, which builds a list of every day from Start of Week to End of Week. The dates are turned into numbers so that the .. operator can produce the range between them.

Custom Column dialog for Dates, building a list from Number.From of Start of Week to Number.From of End of Week

Each row now holds a list in the Dates column.

Working Days, Start of Week and End of Week columns, with a Dates column showing List in every row

  • Expand the Dates column to new rows, so that each record becomes one row per day.
  • Change the type of Dates to Date.
  • Filter Dates to keep only the days from Min_Date to Max_Date:
= Table.SelectRows(#"Changed Type", each [Dates] >= Min_Date and [Dates] <= Max_Date)

Padding each record out to whole weeks makes neighbouring records overlap. Where an employee’s record ends part-way through a week and the next record starts in the same week, both records produce rows for the days in between. In the screenshot below, the boxed dates appear twice for the same employee: once from the record that has ended and once from the record that has started.

Expanded dates for one employee, with two boxed blocks of dates that appear in both the earlier and the later availability record

The duplicate to remove is always the one that falls outside its own record’s start and end dates. Two conditional columns flag those rows:

  • Boundary 1 is 1 where Start Date is after Dates, which means the day comes before the record began.

Add Conditional Column dialog for Boundary 1, returning 1 if Start Date is after Dates and 0 otherwise

  • Boundary 2 is 1 where End Date is before Dates, which means the day comes after the record ended.

Add Conditional Column dialog for Boundary 2, returning 1 if End Date is before Dates and 0 otherwise

Start of Week, End of Week and Dates columns beside Boundary 1 and Boundary 2, showing 1 against the days outside each record’s dates

A day outside its record’s dates is a duplicate only if another record also covers it. To find those days, count how many rows each employee has for each date:

  • Use Group By on User ID and Dates, with two aggregations: Details, using All Rows, and Duplicates, using Count Rows.

Group By dialog in Advanced mode grouping by User ID and Dates, with a Details column of all rows and a Duplicates column counting rows

After grouping, a Duplicates value of 2 marks a date that two records both cover.

Grouped table with User ID, Dates, a Details column of tables and a Duplicates column showing 2 for the overlapping dates

  • Expand Details to bring back every field except User ID and Dates, which the grouped table already has.

Start of Week, End of Week, Boundary 1, Boundary 2 and Duplicates columns after expanding, with alternating rows from the two overlapping records

  • Add a custom column called Remove, which is 1 where the row falls outside its record’s dates and the date is duplicated.

Custom Column dialog for Remove, returning 1 if either boundary flag is 1 and Duplicates is greater than 1

Boundary 1, Boundary 2, Duplicates and Remove columns, with Remove set to 1 on the rows to drop

  • Filter Remove to keep only the zeros, which leaves each employee with one row per date:
= Table.SelectRows(#"Added Remove Duplicates", each ([Remove] = 0))

Rows that fall outside a record’s dates but are not duplicated stay in, such as the days before an employee’s first start date. A later step marks those days as unavailable.

  • Remove the Start of Week, End of Week, Boundary 1, Boundary 2, Duplicates and Remove columns, which are no longer needed.
  • Add Start of Week back, this time calculated from Dates rather than Start Date, with the same country rule for the first day of the week.

Custom Column dialog for Start of Week, using Date.StartOfWeek on Dates with Day.Sunday for the UAE and Day.Monday otherwise

  • Add a Day Name column, from the Add Column tab under Date, Day, Name of Day.

Full or Part, Hrs / Day, Working Days, Start of Week and Day Name columns, one row per employee per day

Step 5: flag the working days for the shortfall check

Section titled “Step 5: flag the working days for the shortfall check”

With one row per employee per day, a series of 1-or-0 columns can now work out which days each employee could work, asked to work and was able to work. Each column builds on the ones before it.

  • Add a With Company? column, which is 1 if the day falls between the record’s Start Date and End Date.

Custom Column dialog for With Company?, returning 1 if Dates is between Start Date and End Date

  • Add a Weekday? column, which is 0 on the weekend. The weekend is Friday and Saturday in the UAE and Saturday and Sunday elsewhere.

Custom Column dialog for Weekday?, returning 0 for Friday and Saturday in the UAE, 0 for Saturday and Sunday elsewhere, and 1 otherwise

  • Use Merge Queries to join the public holidays table on Country and date, with a left outer join so that every day is kept.

Merge dialog joining the availability rows to Public_Holidays on Country and Dates with a left outer join

The merge adds a column holding a table in each row, which contains the matching holiday if there is one.

Day Name, With Company? and Weekday? columns beside a new Holiday_Table column showing Table in each row

  • Expand only the holiday description from that column, and call it Holiday Description. The merge also changes the row order, which is why the query sorts the rows again at the end.

Holiday Description column showing Good Friday and Easter Monday on the matching days and null elsewhere, with the rows no longer in date order

  • Add a conditional column called Public Holiday?, which is 0 where Holiday Description is null and 1 otherwise. A number is easier to use in the calculations that follow than the holiday’s name.

Add Conditional Column dialog for Public Holiday?, returning 0 if Holiday Description equals null and 1 otherwise

Holiday Description beside the new Public Holiday? column, which shows 1 on Good Friday and Easter Monday

  • Add a Can Work? column, which is 1 if the employee was with the company, the day was a weekday and it was not a public holiday.

Custom Column dialog for Can Work?, returning 1 if With Company? is 1, Weekday? is 1 and Public Holiday? is 0

  • Add an Asked to Work? column, which is 1 if the day’s name appears in Working Days.

Custom Column dialog for Asked to Work?, using Text.Contains to test whether Working Days contains Day Name

  • Add an Able to Work? column, which is 1 if the employee both could work and asked to work that day.

Custom Column dialog for Able to Work?, returning 1 if Can Work? and Asked to Work? are both 1

  • Add a Days Left Available to Work? column, which is 1 if Can Work? is greater than Able to Work?. These are days the employee could have worked but did not ask to, which only arises for part-time staff.

Add Conditional Column dialog for Days Left Available to Work?, returning 1 if Can Work? is greater than Able to Work?

  • Use Group By on Start of Week, User ID and Country, and sum each of Can Work?, Asked to Work?, Able to Work? and Days Left Available to Work?.

The grouping leaves out Department on purpose. The method assumes that, within one week in one country, an employee can move freely between departments. So if a part-time employee’s preferred day falls on a holiday, those hours can move to another day in the same week, even if that day is in a different department.

Group By dialog grouping by Start of Week, User ID and Country, with sums of Can Work?, Asked to Work?, Able to Work? and Days Left Available to Work?

Weekly totals by country, showing how many days each employee could work, asked to work, was able to work and had left over

  • Add a Can Work More? column, which is Yes where the employee was able to work fewer days than they asked for and still had at least one spare day that week. Such an employee can make up their agreed days on other days of the week.

Custom Column dialog for Can Work More?, returning Yes if Able to Work? is less than Asked to Work? and Days Left Available to Work? is at least 1, and null otherwise

  • Add a Day Shortfall in Week? column, which gives the number of preferred days the employee lost that week where Can Work More? is Yes.

Custom Column dialog for Day Shortfall in Week?, returning Asked to Work? minus Able to Work? when Can Work More? is Yes, and null otherwise

Asked to Work?, Able to Work? and Days Left Available to Work? columns followed by the new Can Work More? and Day Shortfall in Week? columns

  • Sort by User ID and then by Start of Week.

Weekly rows for one employee sorted by User ID and then Start of Week, moving from UK weeks to UAE weeks

  • Name the query Availability - Day Shortfall Check.

The finished query looks like this:

let
Source = Inventory_Availability_SCD,
#"Fill in End Dates" = Table.ReplaceValue(Source,null, Max_Date,Replacer.ReplaceValue,{"End Date"}),
Monday = Table.ReplaceValue(#"Fill in End Dates","Yes","Monday",Replacer.ReplaceText,{"Mon"}),
Tuesday = Table.ReplaceValue(Monday,"Yes","Tuesday",Replacer.ReplaceText,{"Tue"}),
Wednesday = Table.ReplaceValue(Tuesday,"Yes","Wednesday",Replacer.ReplaceText,{"Wed"}),
Thursday = Table.ReplaceValue(Wednesday,"Yes","Thursday",Replacer.ReplaceText,{"Thu"}),
Friday = Table.ReplaceValue(Thursday,"Yes","Friday",Replacer.ReplaceText,{"Fri"}),
Saturday = Table.ReplaceValue(Friday,"Yes","Saturday",Replacer.ReplaceText,{"Sat"}),
Sunday = Table.ReplaceValue(Saturday,"Yes","Sunday",Replacer.ReplaceText,{"Sun"}),
#"Merged Columns" = Table.CombineColumns(Sunday,{"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"},Combiner.CombineTextByDelimiter(", ", QuoteStyle.None),"Merged Days"),
#"Added Working Days" = Table.AddColumn(#"Merged Columns", "Working Days", each if ([Full or Part] = "Full" and [Country] <> "UAE") then "Monday, Tuesday, Wednesday, Thursday, Friday" else if ([Full or Part] = "Full" and [Country] = "UAE") then "Monday, Tuesday, Wednesday, Thursday, Sunday" else [Merged Days]),
#"Removed Columns" = Table.RemoveColumns(#"Added Working Days",{"Merged Days"}),
#"Inserted Start of Week" = Table.AddColumn(#"Removed Columns", "Start of Week", each if ([Country] = "UAE") then Date.StartOfWeek([Start Date], Day.Sunday) else Date.StartOfWeek([Start Date], Day.Monday)),
#"Inserted End of Week" = Table.AddColumn(#"Inserted Start of Week", "End of Week", each if ([Country] = "UAE") then Date.EndOfWeek([End Date], Day.Sunday) else Date.EndOfWeek([End Date], Day.Monday)),
#"Added Custom" = Table.AddColumn(#"Inserted End of Week", "Dates", each { Number.From([Start of Week])..Number.From([End of Week]) }),
#"Expanded Dates" = Table.ExpandListColumn(#"Added Custom", "Dates"),
#"Changed Type" = Table.TransformColumnTypes(#"Expanded Dates",{{"Dates", type date}}),
#"Filtered Dates" = Table.SelectRows(#"Changed Type", each [Dates] >= Min_Date and [Dates] <= Max_Date),
#"Added Date Boundary 1" = Table.AddColumn(#"Filtered Dates", "Boundary 1", each if [Start Date] > [Dates] then 1 else 0),
#"Added Date Boundary 2" = Table.AddColumn(#"Added Date Boundary 1", "Boundary 2", each if [End Date] < [Dates] then 1 else 0),
#"Grouped Rows1" = Table.Group(#"Added Date Boundary 2", {"User ID", "Dates"}, {{"Details", each _, type table [User ID=text, First Name=text, Last Name=text, Start Date=date, End Date=date, Country=text, Department=text, Full or Part=text, #"[Hrs / Day]"=number, Working Days=text, Start of Week=date, End of Week=date, Dates=date, Boundary 1=number, Boundary 2=number]}, {"Duplicates", each Table.RowCount(_), type number}}),
#"Expanded Details" = Table.ExpandTableColumn(#"Grouped Rows1", "Details", {"First Name", "Last Name", "Start Date", "End Date", "Country", "Department", "Full or Part", "[Hrs / Day]", "Working Days", "Start of Week", "End of Week", "Boundary 1", "Boundary 2"}, {"First Name", "Last Name", "Start Date", "End Date", "Country", "Department", "Full or Part", "[Hrs / Day]", "Working Days", "Start of Week", "End of Week", "Boundary 1", "Boundary 2"}),
#"Added Remove Duplicates" = Table.AddColumn(#"Expanded Details", "Remove", each if ([Boundary 1] = 1 or [Boundary 2] = 1) and ([Duplicates] > 1) then 1 else 0),
#"Filtered Duplicates Out" = Table.SelectRows(#"Added Remove Duplicates", each ([Remove] = 0)),
#"Removed Columns1" = Table.RemoveColumns(#"Filtered Duplicates Out",{"Start of Week", "End of Week", "Boundary 1", "Boundary 2", "Duplicates", "Remove"}),
#"Inserted Start of Week 2" = Table.AddColumn(#"Removed Columns1", "Start of Week", each if ([Country] = "UAE") then Date.StartOfWeek([Dates], Day.Sunday) else Date.StartOfWeek([Dates], Day.Monday)),
#"Inserted Day Name" = Table.AddColumn(#"Inserted Start of Week 2", "Day Name", each Date.DayOfWeekName([Dates]), type text),
#"Added With Company" = Table.AddColumn(#"Inserted Day Name", "With Company?", each if ([Dates] >= [Start Date] and [Dates] <= [End Date]) then 1 else 0),
#"Added Weekday" = Table.AddColumn(#"Added With Company", "Weekday?", each if ([Day Name] = "Friday" or [Day Name] = "Saturday") and ([Country] = "UAE") then 0 else if ([Day Name] = "Saturday" or [Day Name] = "Sunday") and ([Country] <> "UAE") then 0 else 1),
#"Merged Queries" = Table.NestedJoin(#"Added Weekday", {"Country", "Dates"}, Public_Holidays, {"Country", "Date"}, "Holiday_Table", JoinKind.LeftOuter),
#"Expanded Holiday Description" = Table.ExpandTableColumn(#"Merged Queries", "Holiday_Table", {"Description"}, {"Holiday Description"}),
#"Added Public Holiday" = Table.AddColumn(#"Expanded Holiday Description", "Public Holiday?", each if [Holiday Description] = null then 0 else 1),
#"Added Can Work" = Table.AddColumn(#"Added Public Holiday", "Can Work?", each if ([#"With Company?"] = 1 and [#"Weekday?"] = 1 and [#"Public Holiday?"] = 0) then 1 else 0),
#"Added Asked to Work" = Table.AddColumn(#"Added Can Work", "Asked to Work?", each if Text.Contains([Working Days], [Day Name]) then 1 else 0),
#"Added Able to Work" = Table.AddColumn(#"Added Asked to Work", "Able to Work?", each if ([#"Can Work?"] = 1 and [#"Asked to Work?"] = 1) then 1 else 0),
#"Added Days Left Available to Work" = Table.AddColumn(#"Added Able to Work", "Days Left Available to Work?", each if [#"Can Work?"] > [#"Able to Work?"] then 1 else 0),
#"Grouped Rows" = Table.Group(#"Added Days Left Available to Work", {"Start of Week", "User ID", "Country"}, {{"Can Work?", each List.Sum([#"Can Work?"]), type number}, {"Asked to Work?", each List.Sum([#"Asked to Work?"]), type number}, {"Able to Work?", each List.Sum([#"Able to Work?"]), type number}, {"Days Left Available to Work?", each List.Sum([#"Days Left Available to Work?"]), type number}}),
#"Added Can Work More" = Table.AddColumn(#"Grouped Rows", "Can Work More?", each if ([#"Able to Work?"] < [#"Asked to Work?"]) and ([#"Days Left Available to Work?"] >= 1) then "Yes" else null),
#"Added Day Shortfall" = Table.AddColumn(#"Added Can Work More", "Day Shortfall in Week?", each if [#"Can Work More?"] = "Yes" then ([#"Asked to Work?"] - [#"Able to Work?"]) else null),
#"Sorted Rows" = Table.Sort(#"Added Day Shortfall",{{"User ID", Order.Ascending}, {"Start of Week", Order.Ascending}})
in
#"Sorted Rows"

Step 6: expand availability into days for the daily query

Section titled “Step 6: expand availability into days for the daily query”

The Availability - Daily query works out each employee’s available hours for every day. It starts with the same steps as the shortfall check, up to and including the Day Name column.

  • Create a new query and repeat the steps from Step 4, so that the data reaches the same point.

Full or Part, Hrs / Day, Working Days, Start of Week and Day Name columns, matching the shortfall check query at the same step

Step 7: flag the working days for the daily query

Section titled “Step 7: flag the working days for the daily query”

The flag columns from Step 5 are also the same, from With Company? to Days Left Available to Work?. The differences come at the end, because this query keeps one row per day:

  • It does not group by Start of Week, User ID and Country.
  • It does not add Can Work More? or Day Shortfall in Week?, which it takes from the shortfall check query instead.
  • It sorts by User ID and then Dates, rather than by week.

Daily rows sorted by User ID and then Dates, with each employee’s first name, last name and start date

  • Add a step that buffers the sorted table, so that the sort order holds in the steps that follow:
= Table.Buffer(#"Sorted Rows")

The next steps need a running count, within each week, of the spare days in Days Left Available to Work?. A small function does this.

  • Create a new blank query and enter the function below in the Advanced Editor.

Advanced Editor showing the fnRunningTotal function, which takes a table and a column name and returns the table with a running total column added

The function works like the one on the running total page, which explains the technique in more detail, but it takes fewer lines.

It takes two parameters: tbl, the table, and sumcolumn, the name of the column to total. Inside its inner let expression, it:

  1. Buffers the table and stores it as Source.
  2. Renames the column named in sumcolumn to Temp, so that the next step can refer to it by a fixed name.
  3. Uses List.Accumulate over the Temp values to build a list of running totals, which it stores as #"Cumulative Total".
  4. Turns Source into a list of its columns with Table.ToColumns, and appends the running total list to the end with &{#"Cumulative Total"}.
  5. Turns the list of columns back into a table with Table.FromColumns. It takes the column names and types from Source with an extra number column called Days Left Available to Work (Cumulative)?, which it gets by passing the type of Table.AddColumn to Value.Type.
  • Name the query fnRunningTotal. Power Query shows it as a function ready to accept its two parameters.

fnRunningTotal shown as a function with Enter Parameters boxes for tbl and sumcolumn and an Invoke button

  • Back in Availability - Daily, group the buffered table with this step:
= Table.Group(#"Table Buffered", {"Start of Week", "User ID", "Country"}, {{"AllData", (_) => fnRunningTotal(_, "Days Left Available to Work?"), type table}})

The step works as follows:

  • It groups the rows by Start of Week, User ID and Country, so that each group is one employee’s week in one country.
  • For each group, it passes the group’s rows to fnRunningTotal as _, with Days Left Available to Work? as the column to total. The result, a table with the running total column added, goes into a new AllData column.

Clicking a table in AllData shows the new running total column at the end.

Grouped rows with an AllData column of tables, and below them one week’s table ending in a Days Left Available to Work (Cumulative)? column that counts up the spare days

  • Expand AllData with the step below:
= Table.ExpandTableColumn(#"Grouped Rows with Running Total", "AllData", List.RemoveItems(Table.ColumnNames(#"Table Buffered")&{"Days Left Available to Work (Cumulative)?"}, {"Start of Week", "User ID", "Country"}))

Rather than listing the columns by hand, this takes the column names of the buffered table, adds the running total column, and leaves out Start of Week, User ID and Country, which the grouped table already has.

The daily query now brings in the weekly results from the shortfall check, so that it can move lost days onto spare days in the same week.

  • Use Merge Queries to join Availability - Day Shortfall Check on Start of Week, User ID and Country. Do not include Department, for the reason given in Step 5.

Merge dialog joining Availability_Daily to Availability- Day Shortfall Check on Start of Week, User ID and Country with a left outer join

  • Expand only Can Work More? and Day Shortfall in Week?.

Expand dialog with only Can Work More? and Day Shortfall in Week? ticked

  • Replace the nulls in Day Shortfall in Week? with zeros:
= Table.ReplaceValue(#"Expanded Inventory_Table_Weekly",null,0,Replacer.ReplaceValue,{"Day Shortfall in Week?"})
  • Add two custom columns, which together move each lost day onto a spare day in the same week:
    • Shortfall Descending Count subtracts the running total of spare days from the week’s shortfall, for weeks where Can Work More? is Yes. It counts down as the week’s spare days are used up.
    • Able to Still Work? is 1 on a spare day while the count is still below the shortfall and not yet negative. The first spare days of the week, up to the number of days lost, are therefore marked as days the employee can still work.

Custom Column dialog for Shortfall Descending Count, subtracting the cumulative spare days from Day Shortfall in Week? when Can Work More? is Yes, and 0 otherwise

Custom Column dialog for Able to Still Work?, returning 1 if Shortfall Descending Count is below Day Shortfall in Week?, is at least 0, and Days Left Available to Work? is 1

  • Add a Workable Days? column, which adds Able to Work? and Able to Still Work?. It counts the days the employee could work, including the lost days moved elsewhere in the week.

Custom Column dialog for Workable Days?, adding Able to Work? and Able to Still Work?

  • Add an Available Hours column, which multiplies Workable Days? by the hours per day from the availability data.

Custom Column dialog for Available Hours, multiplying Hrs / Day by Workable Days?

  • Remove the columns that are no longer needed:
= Table.RemoveColumns(#"Added Available Hours",{"Full or Part", "Working Days", "Days Left Available to Work (Cumulative)?", "Shortfall Descending Count", "[Hrs / Day]"})
  • Add a Start of Week (Mon) column, whose week always starts on Monday. Start of Week depends on the country, so a report that covers more than one country needs this second column to put every week on the same footing.

Custom Column dialog for Start of Week (Mon), using Date.StartOfWeek on Dates with Day.Monday

  • Move Start of Week (Mon) to the front of the table.
  • Sort by User ID and then Dates again, because the merge changed the order.

Daily availability with Start of Week (Mon) as the first column, followed by Start of Week, User ID, Country and First Name

  • Name the query Availability - Daily.

The finished query looks like this:

let
Source = Inventory_Availability_SCD,
#"Fill in End Dates" = Table.ReplaceValue(Source,null,Max_Date,Replacer.ReplaceValue,{"End Date"}),
Monday = Table.ReplaceValue(#"Fill in End Dates","Yes","Monday",Replacer.ReplaceText,{"Mon"}),
Tuesday = Table.ReplaceValue(Monday,"Yes","Tuesday",Replacer.ReplaceText,{"Tue"}),
Wednesday = Table.ReplaceValue(Tuesday,"Yes","Wednesday",Replacer.ReplaceText,{"Wed"}),
Thursday = Table.ReplaceValue(Wednesday,"Yes","Thursday",Replacer.ReplaceText,{"Thu"}),
Friday = Table.ReplaceValue(Thursday,"Yes","Friday",Replacer.ReplaceText,{"Fri"}),
Saturday = Table.ReplaceValue(Friday,"Yes","Saturday",Replacer.ReplaceText,{"Sat"}),
Sunday = Table.ReplaceValue(Saturday,"Yes","Sunday",Replacer.ReplaceText,{"Sun"}),
#"Merged Columns" = Table.CombineColumns(Sunday,{"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"},Combiner.CombineTextByDelimiter(", ", QuoteStyle.None),"Merged Days"),
#"Added Working Days" = Table.AddColumn(#"Merged Columns", "Working Days", each if ([Full or Part] = "Full" and [Country] <> "UAE") then "Monday, Tuesday, Wednesday, Thursday, Friday" else if ([Full or Part] = "Full" and [Country] = "UAE") then "Monday, Tuesday, Wednesday, Thursday, Sunday" else [Merged Days]),
#"Removed Columns" = Table.RemoveColumns(#"Added Working Days",{"Merged Days"}),
#"Inserted Start of Week" = Table.AddColumn(#"Removed Columns", "Start of Week", each if ([Country] = "UAE") then Date.StartOfWeek([Start Date], Day.Sunday) else Date.StartOfWeek([Start Date], Day.Monday)),
#"Inserted End of Week" = Table.AddColumn(#"Inserted Start of Week", "End of Week", each if ([Country] = "UAE") then Date.EndOfWeek([End Date], Day.Sunday) else Date.EndOfWeek([End Date], Day.Monday)),
#"Added Custom" = Table.AddColumn(#"Inserted End of Week", "Dates", each { Number.From([Start of Week])..Number.From([End of Week]) }),
#"Expanded Dates" = Table.ExpandListColumn(#"Added Custom", "Dates"),
#"Changed Type" = Table.TransformColumnTypes(#"Expanded Dates",{{"Dates", type date}}),
#"Filtered Dates" = Table.SelectRows(#"Changed Type", each [Dates] >= Min_Date and [Dates] <= Max_Date),
#"Added Date Boundary 1" = Table.AddColumn(#"Filtered Dates", "Boundary 1", each if [Start Date] > [Dates] then 1 else 0),
#"Added Date Boundary 2" = Table.AddColumn(#"Added Date Boundary 1", "Boundary 2", each if [End Date] < [Dates] then 1 else 0),
#"Grouped Rows1" = Table.Group(#"Added Date Boundary 2", {"User ID", "Dates"}, {{"Details", each _, type table [User ID=text, First Name=text, Last Name=text, Start Date=date, End Date=date, Country=text, Department=text, Full or Part=text, #"[Hrs / Day]"=number, Working Days=text, Start of Week=date, End of Week=date, Dates=date, Boundary 1=number, Boundary 2=number]}, {"Duplicates", each Table.RowCount(_), type number}}),
#"Expanded Details" = Table.ExpandTableColumn(#"Grouped Rows1", "Details", {"First Name", "Last Name", "Start Date", "End Date", "Country", "Department", "Full or Part", "[Hrs / Day]", "Working Days", "Start of Week", "End of Week", "Boundary 1", "Boundary 2"}, {"First Name", "Last Name", "Start Date", "End Date", "Country", "Department", "Full or Part", "[Hrs / Day]", "Working Days", "Start of Week", "End of Week", "Boundary 1", "Boundary 2"}),
#"Added Remove Duplicates" = Table.AddColumn(#"Expanded Details", "Remove", each if ([Boundary 1] = 1 or [Boundary 2] = 1) and ([Duplicates] > 1) then 1 else 0),
#"Filtered Duplicated Out" = Table.SelectRows(#"Added Remove Duplicates", each ([Remove] = 0)),
#"Removed Columns1" = Table.RemoveColumns(#"Filtered Duplicated Out",{"Start of Week", "End of Week", "Boundary 1", "Boundary 2", "Duplicates", "Remove"}),
#"Inserted Start of Week 2" = Table.AddColumn(#"Removed Columns1", "Start of Week", each if ([Country] = "UAE") then Date.StartOfWeek([Dates], Day.Sunday) else Date.StartOfWeek([Dates], Day.Monday)),
#"Inserted Day Name" = Table.AddColumn(#"Inserted Start of Week 2", "Day Name", each Date.DayOfWeekName([Dates]), type text),
#"Added With Company" = Table.AddColumn(#"Inserted Day Name", "With Company?", each if ([Dates] >= [Start Date] and [Dates] <= [End Date]) then 1 else 0),
#"Added Weekday" = Table.AddColumn(#"Added With Company", "Weekday?", each if ([Day Name] = "Friday" or [Day Name] = "Saturday") and ([Country] = "UAE") then 0 else if ([Day Name] = "Saturday" or [Day Name] = "Sunday") and ([Country] <> "UAE") then 0 else 1),
#"Merged Queries" = Table.NestedJoin(#"Added Weekday", {"Country", "Dates"}, Public_Holidays, {"Country", "Date"}, "Holiday_Table", JoinKind.LeftOuter),
#"Expanded Holiday Description" = Table.ExpandTableColumn(#"Merged Queries", "Holiday_Table", {"Description"}, {"Holiday Description"}),
#"Added Public Holiday" = Table.AddColumn(#"Expanded Holiday Description", "Public Holiday?", each if [Holiday Description] = null then 0 else 1),
#"Added Can Work" = Table.AddColumn(#"Added Public Holiday", "Can Work?", each if ([#"With Company?"] = 1 and [#"Weekday?"] = 1 and [#"Public Holiday?"] = 0) then 1 else 0),
#"Added Asked to Work" = Table.AddColumn(#"Added Can Work", "Asked to Work?", each if Text.Contains([Working Days], [Day Name]) then 1 else 0),
#"Added Able to Work" = Table.AddColumn(#"Added Asked to Work", "Able to Work?", each if ([#"Can Work?"] = 1 and [#"Asked to Work?"] = 1) then 1 else 0),
#"Added Days Left Available to Work" = Table.AddColumn(#"Added Able to Work", "Days Left Available to Work?", each if [#"Can Work?"] > [#"Able to Work?"] then 1 else 0),
#"Sorted Rows" = Table.Sort(#"Added Days Left Available to Work",{{"User ID", Order.Ascending}, {"Dates", Order.Ascending}}),
#"Table Buffered" = Table.Buffer(#"Sorted Rows"),
#"Grouped Rows with Running Total" = Table.Group(#"Table Buffered", {"Start of Week", "User ID", "Country"}, {{"AllData", (_) => fnRunningTotal(_, "Days Left Available to Work?"), type table}}),
#"Expand Relevant Fields" = Table.ExpandTableColumn(#"Grouped Rows with Running Total", "AllData", List.RemoveItems(Table.ColumnNames(#"Table Buffered")&{"Days Left Available to Work (Cumulative)?"}, {"Start of Week", "User ID", "Country"})),
#"Merged Queries1" = Table.NestedJoin(#"Expand Relevant Fields", {"Start of Week", "User ID", "Country"}, #"Availability - Day Shortfall Check", {"Start of Week", "User ID", "Country"}, "Availability_Weekly", JoinKind.LeftOuter),
#"Expanded Inventory_Table_Weekly" = Table.ExpandTableColumn(#"Merged Queries1", "Availability_Weekly", {"Can Work More?", "Day Shortfall in Week?"}, {"Can Work More?", "Day Shortfall in Week?"}),
#"Replaced Value" = Table.ReplaceValue(#"Expanded Inventory_Table_Weekly",null,0,Replacer.ReplaceValue,{"Day Shortfall in Week?"}),
#"Added Shortfall Descending Count" = Table.AddColumn(#"Replaced Value", "Shortfall Descending Count", each if [#"Can Work More?"] = "Yes" then ([#"Day Shortfall in Week?"] - [#"Days Left Available to Work (Cumulative)?"]) else 0),
#"Added Able to Still Work" = Table.AddColumn(#"Added Shortfall Descending Count", "Able to Still Work?", each if ([#"Shortfall Descending Count"] < [#"Day Shortfall in Week?"] and [#"Shortfall Descending Count"] >=0 and [#"Days Left Available to Work?"] = 1) then 1 else 0),
#"Added Workable Days" = Table.AddColumn(#"Added Able to Still Work", "Workable Days?", each [#"Able to Work?"] + [#"Able to Still Work?"]),
#"Added Available Hours" = Table.AddColumn(#"Added Workable Days", "Available Hours", each [#"[Hrs / Day]"]*[#"Workable Days?"]),
#"Removed Columns 2" = Table.RemoveColumns(#"Added Available Hours",{"Full or Part", "Working Days", "Days Left Available to Work (Cumulative)?", "Shortfall Descending Count", "[Hrs / Day]"}),
#"Inserted Start of Week Mon" = Table.AddColumn(#"Removed Columns 2", "Start of Week (Mon)", each Date.StartOfWeek([Dates], Day.Monday), type date),
#"Reordered Columns" = Table.ReorderColumns(#"Inserted Start of Week Mon",{"Start of Week (Mon)", "Start of Week", "User ID", "Country", "First Name", "Last Name", "Start Date", "End Date", "Department", "Dates", "Day Name", "With Company?", "Weekday?", "Holiday Description", "Public Holiday?", "Can Work?", "Asked to Work?", "Able to Work?", "Days Left Available to Work?", "Can Work More?", "Day Shortfall in Week?", "Able to Still Work?", "Workable Days?", "Available Hours"}),
#"Sorted Rows1" = Table.Sort(#"Reordered Columns",{{"User ID", Order.Ascending}, {"Dates", Order.Ascending}})
in
#"Sorted Rows1"

The Availability - Weekly query adds up each employee’s daily availability into weekly hours.

  • Create a new query that references Availability - Daily.
  • Buffer the table, so that the sort order holds through the grouping:
= Table.Buffer(Source)
  • Use Group By on Start of Week (Mon), User ID, First Name, Last Name, Country and Department, and sum each of the flag columns and Available Hours.

Group By dialog grouping by Start of Week (Mon), User ID, First Name, Last Name, Country and Department, with sums of Can Work?, Asked to Work?, Able to Work?, Days Left Available to Work? and Able to Still Work? Lower part of the same Group By dialog, with sums of Able to Still Work?, Workable Days? and Available Hours

The result gives each employee’s available hours by week, with a separate row wherever the employee changed country or department within a week.

Weekly availability by Monday week start, employee, country and department

  • Name the query Availability - Weekly.

The finished query looks like this:

let
Source = #"Availability - Daily",
#"Table Buffered" = Table.Buffer(Source),
#"Grouped Rows" = Table.Group(Table.Buffer(#"Table Buffered"), {"Start of Week (Mon)", "User ID", "First Name", "Last Name", "Country", "Department"}, {{"Can Work?", each List.Sum([#"Can Work?"]), type number}, {"Asked to Work?", each List.Sum([#"Asked to Work?"]), type number}, {"Able to Work?", each List.Sum([#"Able to Work?"]), type number}, {"Days Left Available to Work?", each List.Sum([#"Days Left Available to Work?"]), type number}, {"Able to Still Work?", each List.Sum([#"Able to Still Work?"]), type number}, {"Workable Days?", each List.Sum([#"Workable Days?"]), type number}, {"Available Hours", each List.Sum([Available Hours]), type number}})
in
#"Grouped Rows"

The last query turns the timesheets into hours worked per week, and brings the available hours alongside them.

  • Load the timesheet data into a new query, and remove Column1.

Timesheet data in the Power Query editor, with headings in the first row and nulls in the date columns

  • Add a step that replaces every null or blank cell with 0. It builds a list with one pair per column, each pairing the column’s name with a function that turns null or empty text into 0:
= List.Transform(Table.ColumnNames(#"Removed Columns"), each {_, (_) => if _ = null or _ = "" then 0 else _})
  • Apply that list to the table with Table.TransformColumns, which runs each function on its column:
= Table.TransformColumns(#"Removed Columns", #"ReplacedNullandBlanks")
  • Promote the first row to headers.

Timesheet columns after promoting headers, with zeros in place of the nulls

  • Unpivot every column except User ID, First Name, Last Name and Area of Work:
= Table.UnpivotOtherColumns(#"Promoted Headers", {"User ID", "First Name", "Last Name", "Area of Work"}, "Attribute", "Value")

Unpivoted timesheet with one row per employee, area of work and date, and the hours in a Value column

  • Keep only the rows whose Attribute is a date:
= Table.SelectRows(#"Unpivoted Other Columns", each Text.Contains([Attribute], "/"))
  • Change the type of Attribute to Date/Time.
  • Rename it to Date.
  • Change its type again, to Date.
  • Rename Value to Worked Hours.
  • Add a Start of Week (Mon) column.

Custom Column dialog for Start of Week (Mon), using Date.StartOfWeek on Date with Day.Monday

  • Use Merge Queries to join Availability - Daily, matching Date and User ID to Dates and User ID, which brings in each day’s available hours.

Merge dialog joining the timesheet query to Availability - Daily on Date and User ID with a left outer join

  • Expand Available Hours, Country and Department.

Expand dialog with Available Hours, Country and Department ticked

  • Sort the rows again, because the merge changed the order:
= Table.Sort(#"Expanded Availability_Daily",{{"User ID", Order.Ascending}, {"Date", Order.Ascending}, {"Country", Order.Ascending}, {"Department", Order.Ascending}})
  • Buffer the result, so that the sort order holds through the grouping:
= Table.Buffer(#"Sorted Rows1")
  • Use Group By on Start of Week (Mon), User ID, First Name, Last Name, Country, Department and Area of Work, summing Worked Hours and Available Hours.

Group By dialog grouping by Start of Week (Mon), User ID, First Name, Last Name, Country, Department and a seventh field cut off at the bottom of the list, with sums of Worked Hours and Available Hours

The seventh grouping field, cut off at the bottom of the list, is Area of Work.

The result gives the hours worked and the hours available for each employee, week and area of work.

Weekly rows by employee, country, department and area of work, with Worked Hours and Available Hours side by side

  • Select Close & Load to load the result to a worksheet.

The weekly hours worked and hours available now sit side by side for each employee. Weeks before an employee’s first start date have no country, department or available hours, because the employee was not yet with the company.

Use by Week table in Excel, listing week start, employee, country, department and area of work with worked and available hours

The finished query looks like this:

let
Source = Excel.CurrentWorkbook(),
Inventory_Use = Source{[Name="Inventory_Use"]}[Content],
#"Filtered Rows" = Table.SelectRows(Inventory_Use, each ([Column3] <> null)),
#"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Column1"}),
#"ReplacedNullandBlanks" = List.Transform(Table.ColumnNames(#"Removed Columns"), each {_, (_) => if _ = null or _ = "" then 0 else _}),
#"TransformColumns" = Table.TransformColumns(#"Removed Columns", #"ReplacedNullandBlanks"),
#"Promoted Headers" = Table.PromoteHeaders(TransformColumns, [PromoteAllScalars=true]),
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Promoted Headers", {"User ID", "First Name", "Last Name", "Area of Work"}, "Attribute", "Value"),
#"Filtered Rows1" = Table.SelectRows(#"Unpivoted Other Columns", each Text.Contains([Attribute], "/")),
#"Changed Type" = Table.TransformColumnTypes(#"Filtered Rows1",{{"Attribute", type datetime}}),
#"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"Attribute", "Date"}}),
#"Changed Type1" = Table.TransformColumnTypes(#"Renamed Columns",{{"Date", type date}, {"Value", type number}}),
#"Renamed Columns1" = Table.RenameColumns(#"Changed Type1",{{"Value", "Worked Hours"}}),
#"Inserted Start of Week (Mon)" = Table.AddColumn(#"Renamed Columns1", "Start of Week (Mon)", each Date.StartOfWeek([Date], Day.Monday), type date),
#"Merged Queries" = Table.NestedJoin(#"Inserted Start of Week (Mon)", {"Date", "User ID"}, #"Availability - Daily", {"Dates", "User ID"}, "Availability_Daily", JoinKind.LeftOuter),
#"Expanded Availability_Daily" = Table.ExpandTableColumn(#"Merged Queries", "Availability_Daily", {"Available Hours", "Country", "Department"}, {"Available Hours", "Country", "Department"}),
#"Sorted Rows1" = Table.Sort(#"Expanded Availability_Daily",{{"User ID", Order.Ascending}, {"Date", Order.Ascending}, {"Country", Order.Ascending}, {"Department", Order.Ascending}}),
#"Buffered Table" = Table.Buffer(#"Sorted Rows1"),
#"Grouped Rows" = Table.Group(#"Buffered Table", {"Start of Week (Mon)", "User ID", "First Name", "Last Name", "Country", "Department", "Area of Work"}, {{"Worked Hours", each List.Sum([Worked Hours]), type nullable number}, {"Available Hours", each List.Sum([Available Hours]), type nullable number}})
in
#"Grouped Rows"

From this final table, a utilisation table and chart can be built, with utilisation calculated as hours worked divided by hours available.

Utilisation table by week and employee, showing available hours, hours and utilisation for each area of work, total hours worked, and overall utilisation coloured by level

Stacked column chart of weekly utilisation by area of work, with slicers for department, country and user ID

The DAX page Showing HR Inventory Utilisation over time builds a report on this data that shows each employee’s utilisation.

The same approach can be taken further in several directions:

  • Other time periods. Utilisation can be reported by month, or by hour, which would show day and night shifts separately.
  • More employee fields. Fields such as job grade, office, and freelance or permanent status can be added to the availability data beside Country and Department, where the HR system records them.
  • More timesheet fields. Project codes, internal codes and status codes on the timesheets would allow finer tracking, again where the system supports them.
  • Annual leave and time off in lieu. These also reduce availability. For past dates, the hours will usually already be on the timesheets and can be taken from there. For future dates they may not be, so they would need to come from a separate annual leave report.