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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

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
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

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 community update carousel

Fabric Community Update - June 2025

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