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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
Vatz8
Helper I
Helper I

Split datetime columns into multiple rows for each day.

Hi,

I want to split the datetime columns range into multiple rows as shown below.

 

ID|     punch_Start                     | punch_End
--------------------------------------------
A | 2019-03-04 23:18:00| 2019-03-04 23:21:00
--------------------------------------------
A | 2019-03-04 23:45:00| 2019-03-05 00:15:00
--------------------------------------------

 

Required Output-

ID|       punch_Start                   | punch_End
--------------------------------------------
A | 2019-03-04 23:18:00| 2019-03-04 23:21:00
--------------------------------------------
A | 2019-03-04 23:45:00| 2019-03-04 23:59:00
--------------------------------------------
A | 2019-03-04 23:59:00| 2019-03-05 00:00:00
--------------------------------------------
A | 2019-03-05 00:00:00| 2019-03-05 00:15:14

 

 

Please let me know how can I achieve this.

2 REPLIES 2
AlienSx
Super User
Super User

Hi, @Vatz8 

let
    Source = your_last_step,
    types = Table.TransformColumnTypes(Source,{{"punch_Start", type datetime}, {"punch_End", type datetime}}),
    f = (lst as list) =>
        [id = lst{0},
        end = lst{2},
        gen = 
            List.Buffer(
                List.Generate(
                    () => lst{1},
                    (x) => x < end,
                    (x) => 
                        if DateTime.Time(x) = #time(23, 59, 00) 
                        then x + #duration(0, 0, 1, 0)
                        else DateTime.From(DateTime.Date(x)) + #duration(0, 23, 59, 0)
                )
            ),
        dts = List.Zip({List.Repeat({id}, List.Count(gen)), gen, List.RemoveFirstN(gen, 1) & {end}})][dts],
    rows = List.Buffer(Table.ToRows(types)),
    txform_rows = List.Combine(List.Transform(rows, f)),
    z = Table.FromRows(txform_rows, Table.ColumnNames(Source))
in
    z
PhilipTreacy
Super User
Super User

@Vatz8 

 

Please don't cross post your questions

 

Split Datetime range columns into multiple rows fo... - Microsoft Fabric Community

 

Thanks

 

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

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