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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Maha1
Helper II
Helper II

Merge tables where Date is between Start and End dates

I have a Master Table that include list of employees and I want to see who went on an assignment during the Date Period. I want to emphasize that not all employees went on assignment, which mean that not all employees are included in the Assignment Table and I don't want to filter them from the Master Sheet. Below is an example:

 

Master Table:

 

Maha1_0-1689174684444.png

 

Assignment Table:

 

Maha1_1-1689174853019.png

 

Master Table after merging should look like this:

 

Maha1_2-1689174974938.png

 

 

1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

Assignment:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQyVtJRMtQ31DcyMDICMY1g7FgdoLShIYoYgm2sFBsLAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Employee = _t, startDate = _t, endDate = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"startDate", type date}, {"endDate", type date}})
in
    #"Changed Type"

Master:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQyVtJRMtQ31DcyADJjdRBCRphCxgghIyMjdFUwISRVhoaGKEKxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Employee = _t, #"Date Period" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date Period", type date}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Table.SelectRows(Assignment,(k)=>k[Employee]=[Employee] and k[startDate]<=[Date Period] and k[endDate]>=[Date Period])),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Added Custom", "Custom", {"startDate", "endDate"}, {"startDate", "endDate"})
in
    #"Expanded Custom"

View solution in original post

3 REPLIES 3
lbendlin
Super User
Super User

Assignment:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQyVtJRMtQ31DcyMDICMY1g7FgdoLShIYoYgm2sFBsLAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Employee = _t, startDate = _t, endDate = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"startDate", type date}, {"endDate", type date}})
in
    #"Changed Type"

Master:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQyVtJRMtQ31DcyADJjdRBCRphCxgghIyMjdFUwISRVhoaGKEKxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Employee = _t, #"Date Period" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date Period", type date}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Table.SelectRows(Assignment,(k)=>k[Employee]=[Employee] and k[startDate]<=[Date Period] and k[endDate]>=[Date Period])),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Added Custom", "Custom", {"startDate", "endDate"}, {"startDate", "endDate"})
in
    #"Expanded Custom"

@lbendlin Thank you for the solution. However, please recommend another solution for large data? My Master table contain 24 million rows and its been an hour and only 500k is loaded as of now.
Thanks again.

Please provide meaningful amounts of sample data.

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

Top Solution Authors
Top Kudoed Authors