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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
aidenblake
Frequent Visitor

Merge timestamp table with startdate-enddate table

I have two tables which I like to merge or at least connect to each other based on the date columns.

Both tables don't have any other columns in common

 

First Table contains a start - and enddate, with Variable-Values (1,2 and 3):

 

StartDateEndDateVar1Var2Var3
25.03.2022  30.09.2022  135
01.10.2022  31.12.2022  246

 

My second table contains timestamp column, with other 3 variables:

TimestampVar4Var5Var6
25.03.2022 13:45  1.534
25.03.2022 14:003.423
25.03.2022 14:153.445
31.12.2022 23:153.235
31.12.2022 23:304.334
31.12.2022 23:453.443

Now I want a resulting table, which looks like this:

 

TimestampVar4Var5Var6Var1Var2Var3
25.03.2022 13:45  1.534135
25.03.2022 14:003.423135
25.03.2022 14:153.445135
31.12.2022 23:153.235246
31.12.2022 23:304.334246
31.12.2022 23:453.443246

How can I achieve this in PowerBI?

1 ACCEPTED SOLUTION
AlB
Community Champion
Community Champion

@aidenblake 

See it all at work in the attached file. Place the following M code in a blank query to see the steps.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bc5LCsAwCATQqwTXRXTUTa4Scv9r1KQfkHYxs/HBOAYhWIwhQFPrHq3RQcqRbRmneVTkXWQd2bOx2ZdovGQlNjFlxUVgD8E99EdsDTlb+aUSr0P5yzwB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Timestamp = _t, Var4 = _t, Var5 = _t, Var6 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{ {"Var4", type number}, {"Var5", Int64.Type}, {"Var6", Int64.Type}}),
    #"Changed Type with Locale" = Table.TransformColumnTypes(#"Changed Type", {{"Timestamp", type datetime}}, "en-GB"),

    #"Added Custom" = Table.AddColumn(#"Changed Type with Locale", "Custom", each Table.SelectRows(Table1, (inner)=> Date.From([Timestamp])>= inner[StartDate] and Date.From([Timestamp])<= inner[EndDate])),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Added Custom", "Custom", {"Var1", "Var2", "Var3"}, {"Var1", "Var2", "Var3"})
in
    #"Expanded Custom"

 

SU18_powerbi_badge

Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

 

View solution in original post

3 REPLIES 3
AlB
Community Champion
Community Champion

@aidenblake 

See it all at work in the attached file. Place the following M code in a blank query to see the steps.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bc5LCsAwCATQqwTXRXTUTa4Scv9r1KQfkHYxs/HBOAYhWIwhQFPrHq3RQcqRbRmneVTkXWQd2bOx2ZdovGQlNjFlxUVgD8E99EdsDTlb+aUSr0P5yzwB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Timestamp = _t, Var4 = _t, Var5 = _t, Var6 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{ {"Var4", type number}, {"Var5", Int64.Type}, {"Var6", Int64.Type}}),
    #"Changed Type with Locale" = Table.TransformColumnTypes(#"Changed Type", {{"Timestamp", type datetime}}, "en-GB"),

    #"Added Custom" = Table.AddColumn(#"Changed Type with Locale", "Custom", each Table.SelectRows(Table1, (inner)=> Date.From([Timestamp])>= inner[StartDate] and Date.From([Timestamp])<= inner[EndDate])),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Added Custom", "Custom", {"Var1", "Var2", "Var3"}, {"Var1", "Var2", "Var3"})
in
    #"Expanded Custom"

 

SU18_powerbi_badge

Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

 

AlB
Community Champion
Community Champion

Hi @aidenblake 

Do you want this in DAX or in Power Query?

I guess the end_date on the first row of the first table should be 25.03.2022 instead?

Please share a sample of the first two tables in text-tabular format instead of on a screen cap so that the contents can be copied and a solution built

 

SU18_powerbi_badge

Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

 

There were some mistakes, which are now corrected. In Power Query, but if it's easier in DAX, that would be fine for me too - I'm happy if there is even one solution.

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.