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
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
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.