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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register 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
Super User
Super User

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!

If my answer helped solve your issue, please consider marking it as the accepted solution. It helps others in the community find answers faster—and keeps the community growing stronger!
You can also check out my YouTube channel for tutorials, tips, and real-world solutions in Power Query with the following link
https://youtube.com/@omidbi?si=96Bo-ZsSwOx0Z36h

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
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.