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 source data
Section titled “The source data”Availability
Section titled “Availability”The first source is an availability table exported from the HR system.

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.
Public holidays
Section titled “Public holidays”The second source lists the public holidays for each country, either exported from the HR system or typed in by hand.

Timesheets
Section titled “Timesheets”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.

How the queries fit together
Section titled “How the queries fit together”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.
Step 1: list the timesheet dates
Section titled “Step 1: list the timesheet dates”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.

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

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

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

- 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)
- 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)"Step 2: find the first date
Section titled “Step 2: find the first date”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.

Step 3: find the last date
Section titled “Step 3: find the last date”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.

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.

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

- In the Mon column, replace Yes with Monday.

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

- 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")
- 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.


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

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

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

Each row now holds a list in the Dates column.

- 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)Remove the overlapping days
Section titled “Remove the overlapping days”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.

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.

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


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.

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

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

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


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

- Add a Day Name column, from the Add Column tab under Date, Day, Name of 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.

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

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

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

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

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

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

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

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

Total the flags by week
Section titled “Total the flags by week”- 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.


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

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


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

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

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.

- Add a step that buffers the sorted table, so that the sort order holds in the steps that follow:
= Table.Buffer(#"Sorted Rows")Step 8: add a running total of spare days
Section titled “Step 8: add a running total of spare days”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.

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:
- Buffers the table and stores it as
Source. - Renames the column named in
sumcolumnto Temp, so that the next step can refer to it by a fixed name. - Uses
List.Accumulateover the Temp values to build a list of running totals, which it stores as#"Cumulative Total". - Turns
Sourceinto a list of its columns withTable.ToColumns, and appends the running total list to the end with&{#"Cumulative Total"}. - Turns the list of columns back into a table with
Table.FromColumns. It takes the column names and types fromSourcewith an extra number column called Days Left Available to Work (Cumulative)?, which it gets by passing the type ofTable.AddColumntoValue.Type.
- Name the query fnRunningTotal. Power Query shows it as a function ready to accept its two parameters.

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

- 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.
Step 9: move lost days onto spare days
Section titled “Step 9: move lost days onto spare days”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.

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

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


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

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

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

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

- 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"Step 10: total availability by week
Section titled “Step 10: total availability by week”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.

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

- 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"Step 11: total hours worked by week
Section titled “Step 11: total hours worked by week”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.

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

- 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")
- 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.

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

- Expand Available Hours, Country and Department.

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

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.

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

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"Reporting utilisation
Section titled “Reporting utilisation”From this final table, a utilisation table and chart can be built, with utilisation calculated as hours worked divided by hours available.


The DAX page Showing HR Inventory Utilisation over time builds a report on this data that shows each employee’s utilisation.
Extending the method
Section titled “Extending the method”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.