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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
jones_lilly
Frequent Visitor

Combine 2 tables based on datetime in one table falling between start/end datetime columns in other

Hi,

 

The following Table A has a start and end DateTime column (Event Frame Start Time & Event Frame End Time):

jones_lilly_0-1633696922842.png

I then have the following Table B: 

jones_lilly_1-1633697113142.png

Is it possible to create a new table (or combine), which contains the ID_1, Event Frame Start Time, Event Frame End Time from Table A and the Date_Time & Category from Table B IF any of the Date_Time rows falls between Event Frame Start Time and Event Frame End Time?

 

 

Thanks,

Conor

 

1 ACCEPTED SOLUTION
wdx223_Daniel
Super User
Super User

New DAX Query=GENERATE(TableA,FILTER(SUMMARISE(TableB,TableB[Date_Time],TableB[Category]),TableB[Date_Time]>=TableA[Event Frame Start Time]&&TableB[Date_Time]<=TableA[Event Frame End Time]))

View solution in original post

2 REPLIES 2
wdx223_Daniel
Super User
Super User

New DAX Query=GENERATE(TableA,FILTER(SUMMARISE(TableB,TableB[Date_Time],TableB[Category]),TableB[Date_Time]>=TableA[Event Frame Start Time]&&TableB[Date_Time]<=TableA[Event Frame End Time]))

jennratten
Super User
Super User

Hello - this is how you can add ID_1, StartTime and EndTime from TableA to TableB for rows in which the DateTime is between the Start and End Times from TableA.

 

TableA

jennratten_0-1633705636800.png

 

TableB Before

jennratten_2-1633705688441.png

 

TableB After

jennratten_1-1633705670294.png

 

Table A Script

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUXJ0dASShvqG+kYGRgYKJlYGBgW5YBFjqJChEVBMASgYqxOtZASUcnJyApJGyFoUwHqM9I0s0PXEAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, ID_1 = _t, StartTime = _t, EndTime = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"ID_1", type text}, {"StartTime", type datetime}, {"EndTime", type datetime}})
in
    #"Changed Type"

 

TableB Script

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtQ31DcyMDJQMLEyMAAihQBfJR0l54zEvPRUIMPLxd9VKVYnWskEps7QCKSqIBdTVSwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [DateTime = _t, Event = _t, User = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"DateTime", type datetime}, {"Event", type text}, {"User", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Table.SelectRows(TableA, (x)=> x[StartTime]<=[DateTime] and x[EndTime]>=[DateTime])),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Added Custom", "Custom", {"ID_1", "StartTime", "EndTime"})
in
    #"Expanded Custom"

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.