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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
kwidhiya
New Member

How to Create and Add Row between dates and cut the value by daily hours

Hi All,

 

I really need all of your help for this one,

I have sample data like this

kwidhiya_0-1631417086256.png

I want to expand between the Start_Time and End_Time and re-calculate the duration by the day,

What i want is like this data below

kwidhiya_1-1631417164800.png

For your additional information,

My cut off time for daily is every 06:00:00 AM

 

Thanks for your help, i love this community and if you need any information just ask me!

 

Thank You!

1 ACCEPTED SOLUTION
Fowmy
Super User
Super User

@kwidhiya 

I create a column with flexibility for any start and end time, please check and update here.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjTSNbDUNTJU0lEKyk9PLQLS4flF2UAKJqNgaWVgAOKbQPkWVsYgvom5nqlSbCwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Name = _t, Status = _t, #"Start Time" = _t, #"End Time" = _t, #"Duration (Hours)" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Name", type text}, {"Status", type text}, {"Start Time", type datetime}, {"End Time", type datetime}, {"Duration (Hours)", type number}},"en-gb"),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each let

    s = [Start Time],
    e = [End Time],
    v1 = Date.StartOfDay([Start Time]) + #duration(0,6,0,0),
    v2 = if s < v1 then v1 else Date.StartOfDay([Start Time]) + #duration(1,6,0,0),
    Final = 
         
      List.Combine(
        {
            List.Generate(
                    ()=>  v2,
                    each _ < e,
                    each _ + #duration(0,24,0,0)
                )
            ,
            {e}
        }  
    )
in
Table.AddColumn(
    Table.SelectRows(   
        Table.FromColumns( { List.Combine( { {s} , List.Skip(Final,0)} ),List.Skip(Final,0)}, {"Start","End"} ),
        each _[End] <> null
    ),
    "Duration",
    each Number.From(([End] - [Start])*24)  
)),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Added Custom", "Custom", {"End", "Duration"}, {"End", "Duration"})
in
    #"Expanded Custom"

 

Fowmy_0-1631459590894.png

 

 

 The file is attached below my signature.

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

3 REPLIES 3
Fowmy
Super User
Super User

@kwidhiya 

I create a column with flexibility for any start and end time, please check and update here.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjTSNbDUNTJU0lEKyk9PLQLS4flF2UAKJqNgaWVgAOKbQPkWVsYgvom5nqlSbCwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Name = _t, Status = _t, #"Start Time" = _t, #"End Time" = _t, #"Duration (Hours)" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Name", type text}, {"Status", type text}, {"Start Time", type datetime}, {"End Time", type datetime}, {"Duration (Hours)", type number}},"en-gb"),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each let

    s = [Start Time],
    e = [End Time],
    v1 = Date.StartOfDay([Start Time]) + #duration(0,6,0,0),
    v2 = if s < v1 then v1 else Date.StartOfDay([Start Time]) + #duration(1,6,0,0),
    Final = 
         
      List.Combine(
        {
            List.Generate(
                    ()=>  v2,
                    each _ < e,
                    each _ + #duration(0,24,0,0)
                )
            ,
            {e}
        }  
    )
in
Table.AddColumn(
    Table.SelectRows(   
        Table.FromColumns( { List.Combine( { {s} , List.Skip(Final,0)} ),List.Skip(Final,0)}, {"Start","End"} ),
        each _[End] <> null
    ),
    "Duration",
    each Number.From(([End] - [Start])*24)  
)),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Added Custom", "Custom", {"End", "Duration"}, {"End", "Duration"})
in
    #"Expanded Custom"

 

Fowmy_0-1631459590894.png

 

 

 The file is attached below my signature.

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

tex628
Community Champion
Community Champion

HI @kwidhiya , 

Give this Power Query column a try:

let 
StartDown = Number.RoundDown(Number.From([Start_Time])) + 0.25,
EndDown = Number.RoundDown(Number.From([End_Time])) + 0.25,
Start = Number.From([Start_Time]), 
End = Number.From([End_Time]),
Addition1 = if Start<StartDown then 1 else 0,
Addition2 = if End>EndDown then 1 else 0
in
List.Transform(
List.Numbers( 
    StartDown , EndDown - StartDown + Addition1 + Addition2 ) , 
    each 
    if _ = StartDown then 
    if Start < StartDown then (StartDown - Start) * 24
    else ((StartDown+1) - Start) * 24

    else if _ = EndDown then 
    if End > EndDown then ((End - EndDown) * 24)
    else 24 - ((EndDown - End) * 24)

    else 24
    )


Br, 
Johannes


Connect on LinkedIn
AllisonKennedy
Super User
Super User

@kwidhiya 

 

Using this method: https://excelwithallison.blogspot.com/2020/06/dax-approximate-lookup.html

 

See attached file below signature. 

 

I added a 'Start of Day' and 'End of Day' columns to the DimDate table, then it should work with your current data model if the date table is UNRELATED to the Hours table. 

 


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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 Solution Authors