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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

Distribute rows hour wise

Hi Everyone, 

 

I am having a table where I get timestamps for the tasks

 

Taskfm_dttm to_dttm
A12/31/2021 21:50 12/31/2021 22:10
B10/21/2021 17:55 10/21/2021 18:05
E6/15/2021 14:48 6/15/2021 15:02


I trying to get the following outputs in power query:

TejaswiniDahat_0-1623763457027.png

 

Thanks 

1 ACCEPTED SOLUTION
CNENFRNL
Community Champion
Community Champion

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Xc2xDYAwDETRVZBrJJ9NDJY7iJgiyv5rEEIa0r5/0pVCJ60kypuwQmVRCcNEGgKqa6HrDWAdQY4wm8gD1rd3CzuLDU+R/C8W0L7M+Qs+AgI+S/up9QE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Task = _t, fm_dttm = _t, to_dttm = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Task", type text}, {"fm_dttm", type datetime}, {"to_dttm", type datetime}}),
    #"Added Custom" =
        let 
            EoH = (dttm as datetime) => DateTime.Date(DateTime.Date(dttm)) & #time(Time.Hour(DateTime.Time(dttm)),59,0)
        in
            Table.AddColumn(#"Changed Type", 
                "Custom", 
                each
                let _to = EoH([fm_dttm]) 
                in Table.FromRecords(
                    if _to>=[to_dttm] then {[fm=[fm_dttm], to=[to_dttm]]}
                        else List.Generate(
                            () => [fm=[fm_dttm], to=_to],
                            (x) => x[to]<[to_dttm],
                            (y) => [fm=y[to]+#duration(0,0,1,0), to=EoH(fm)]
                        ) & {[fm=to-#duration(0,0,Time.Minute(DateTime.Time([to_dttm])),0), to=[to_dttm]]}
                )
            ),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"fm_dttm", "to_dttm"}),
    #"Expanded Table" = Table.ExpandTableColumn(#"Removed Columns", "Custom", {"fm", "to"}, {"fm", "to"})
in
    #"Expanded Table"

Screenshot 2021-06-15 174441.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

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Xc2xDYAwDETRVZBrJJ9NDJY7iJgiyv5rEEIa0r5/0pVCJ60kypuwQmVRCcNEGgKqa6HrDWAdQY4wm8gD1rd3CzuLDU+R/C8W0L7M+Qs+AgI+S/up9QE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Task = _t, fm_dttm = _t, to_dttm = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Task", type text}, {"fm_dttm", type datetime}, {"to_dttm", type datetime}}),
    #"Added Custom" =
        let 
            EoH = (dttm as datetime) => DateTime.Date(DateTime.Date(dttm)) & #time(Time.Hour(DateTime.Time(dttm)),59,0)
        in
            Table.AddColumn(#"Changed Type", 
                "Custom", 
                each
                let _to = EoH([fm_dttm]) 
                in Table.FromRecords(
                    if _to>=[to_dttm] then {[fm=[fm_dttm], to=[to_dttm]]}
                        else List.Generate(
                            () => [fm=[fm_dttm], to=_to],
                            (x) => x[to]<[to_dttm],
                            (y) => [fm=y[to]+#duration(0,0,1,0), to=EoH(fm)]
                        ) & {[fm=to-#duration(0,0,Time.Minute(DateTime.Time([to_dttm])),0), to=[to_dttm]]}
                )
            ),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"fm_dttm", "to_dttm"}),
    #"Expanded Table" = Table.ExpandTableColumn(#"Removed Columns", "Custom", {"fm", "to"}, {"fm", "to"})
in
    #"Expanded Table"

Screenshot 2021-06-15 174441.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!

Anonymous
Not applicable

Thanks alot..

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 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.

Top Kudoed Authors