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
RichardJ
Responsive Resident
Responsive Resident

Merging table in Power Query using a timestamp between two timestamp values in calendar table

Hi,

Please could someone advise if/how it is possible in Power Query to merge a column from a table where a timestamp is within a date/time range on another table.

 

In the pbix i've created a Production Calendar table (6am Friday til 5:59:59am the following Friday) and have a Measurements table where i'd like to find the Production Week for the Measurement from the Calendar table.

 

PBIX can be found here

https://www.dropbox.com/s/itxcl36x34zuk93/Production%20Week%20Calendar.pbix?dl=0

 

Question as below

Merge QuestionMerge Question

 

Thanks,

Richard

1 ACCEPTED SOLUTION
CNENFRNL
Community Champion
Community Champion

Easy enough

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtQ3NNA3MjAyUDC1MrW0MjBQcPRV0lEyNAASAYnFxUAKJBtvYKQUq4Os3Ayo1srAEKrcEF25MZpyC7BymOlGQMItMTMHWXksAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [TimeStamp = _t, Measurement = _t, Quality = _t, #"Desired Result" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"TimeStamp", type datetime}, {"Measurement", Int64.Type}}),

    #"Added YrWk" = Table.AddColumn(#"Changed Type", "YrWk", each let dt = Date.From([TimeStamp] - #duration(0,6,0,-1)) in Number.ToText(Date.Year(dt)*100 + Date.WeekOfYear(dt, Day.Friday), "0000_00"))
in
    #"Added YrWk"

CNENFRNL_0-1672509899605.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

View solution in original post

2 REPLIES 2
CNENFRNL
Community Champion
Community Champion

Easy enough

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtQ3NNA3MjAyUDC1MrW0MjBQcPRV0lEyNAASAYnFxUAKJBtvYKQUq4Os3Ayo1srAEKrcEF25MZpyC7BymOlGQMItMTMHWXksAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [TimeStamp = _t, Measurement = _t, Quality = _t, #"Desired Result" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"TimeStamp", type datetime}, {"Measurement", Int64.Type}}),

    #"Added YrWk" = Table.AddColumn(#"Changed Type", "YrWk", each let dt = Date.From([TimeStamp] - #duration(0,6,0,-1)) in Number.ToText(Date.Year(dt)*100 + Date.WeekOfYear(dt, Day.Friday), "0000_00"))
in
    #"Added YrWk"

CNENFRNL_0-1672509899605.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

RichardJ
Responsive Resident
Responsive Resident

@CNENFRNL Now that is a beautiful solution - No Merge required.
Nice work and thanks for the lesson.

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.