Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
FrankJust
Regular Visitor

Append two tables with overlapping date ranges

Hi,

 

I'm trying to create a report that will calculate the FTE of a group of staff at a particular date, as well as showing the FTE minus absences.

 

My problem is that I have two tables. One is a staff list, with a new row whenever there is a change in an employees data along with the start and end dates (e.g. changing job or moving location). The second is a table of absences again with a start and end date.

 

I ideally want to append these tables in Power Query and resolve any overlapping date ranges.

 

So if a given employee is in post 01/01/2020 to 31/12/2022, but is absent 01/06/2021 to 30/06/2021, I would want to end up with three rows like so:

 

SIP Table

EmployeeFTEAbsenceStart DateEnd Date
A1 01/01/202031/12/2022

 

Absence Table

EmployeeAbsenceStart DateEnd Date
ASickness01/06/202130/06/2021

 

Appended Table (Ideally)

EmployeeFTEAbsenceStart DateEnd Date
A1 01/01/202031/05/2021
A1Sickness01/06/202130/06/2021
A1 01/07/202131/12/2022

 

In effect this would generate the dates in bold italic.

 

My main issue is my actual data would involve ~3000 rows and any attempts I've made have rapidly slowed the query beyond what is practical.

 

Any help with achieving this would be massively appreciated, thank you in advance.

1 ACCEPTED SOLUTION
jgeddes
Super User
Super User

Here is a pbix file with one method you could use. It will likely need to be amended once additional employees are introduced but the general idea should work.

jgeddes_0-1728500677638.pngjgeddes_1-1728500695203.pngjgeddes_2-1728500707850.png

 




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





View solution in original post

5 REPLIES 5
Omid_Motamedise
Memorable Member
Memorable Member

See this solution

let
    Table1 = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTIEYgUgNjDUByIjAyMDIMfYUN/QCMQxUoqNBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Employee = _t, FTE = _t, Absence = _t, #"Start Date" = _t, #"End Date" = _t]),
    ChangedType_T1 = Table.TransformColumnTypes(Table1,{{"Employee", type text}, {"FTE", Int64.Type}, {"Absence", type text}, {"Start Date", type date}, {"End Date", type date}}),
     Table2 = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUQrOTM7OSy0uBjINDPUNzPSNDIwMgRxjAzgnNhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Employee = _t, Absence = _t, #"Start Date" = _t, #"End Date" = _t]),
    ChangedType_T2 = Table.TransformColumnTypes(Table2,{{"Employee", type text}, {"Absence", type text}, {"Start Date", type date}, {"End Date", type date}}),
    Custom1 = ChangedType_T2 & ChangedType_T1,
    #"Grouped Rows" = Table.Group(Custom1, {"Employee"}, {"Count", each [a=Table.Buffer(Table.AddIndexColumn(Table.Sort(_,{{"Start Date", Order.Ascending}, {"End Date", Order.Ascending}}),"i")),b=Table.AddColumn(a,"New EndDate",(x)=>try a[Start Date]{x[i]+1}-#duration(1,0,0,0) otherwise x[End Date])][b]}),
    #"Expanded Count" = Table.ExpandTableColumn(#"Grouped Rows", "Count", {"Absence", "Start Date", "End Date", "FTE", "i", "New EndDate"}, {"Absence", "Start Date", "End Date", "FTE", "i", "New EndDate"}),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded Count",{"End Date", "i"})
in
    #"Removed Columns"

If this answer helped resolve your issue, please consider marking it as the accepted answer. And if you found my response helpful, I'd appreciate it if you could give me kudos. Thank you!

Thank you for the help, it's hugely appreciated. At the moment the above solution from jgeddes is working for me. But I may revisit your method 

jgeddes
Super User
Super User

Here is a pbix file with one method you could use. It will likely need to be amended once additional employees are introduced but the general idea should work.

jgeddes_0-1728500677638.pngjgeddes_1-1728500695203.pngjgeddes_2-1728500707850.png

 




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





This looks like it works for me. Thank you again!

Thank you, I'll take a look at this tomorrow. Appreciate the help!

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.