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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
AllanBerces
Post Prodigy
Post Prodigy

Hours Distribution Start to End

Hi good day,

Can anyone help me if it possible to distribute the hours from start to end date of certain activity.

 

AllanBerces_0-1741858037090.png

DESIRED OUTPUT

 

AllanBerces_1-1741858117475.png

OR

AllanBerces_2-1741858230987.png

 

Thank you

2 ACCEPTED SOLUTIONS
Deku
Super User
Super User

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTI00jfUNzQCsUxhLFMDpVidaCUjiLQRVNpI3xjKMgDKxwIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [activity = _t, start = _t, end = _t, hours = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"activity", Int64.Type}, {"start", type date}, {"end", type date}, {"hours", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Date", each List.Dates([start], Duration.Days([end] - [start]) + 1 , #duration(1, 0, 0, 0))),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Hours Per day", each [hours] / List.Count( [Date] )),
    #"Expanded Date" = Table.ExpandListColumn(#"Added Custom1", "Date"),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded Date",{"start", "end", "hours"})
in
    #"Removed Columns"

from 

Deku_0-1741859202661.png

To

Deku_1-1741859222030.png

 


Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!

View solution in original post

Ashish_Mathur
Super User
Super User

Hi,

This M code works

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Activity", Int64.Type}, {"Hours", Int64.Type}, {"Est Stat Date", type date}, {"Est End Date", type date}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each {Number.From([Est Stat Date])..Number.From([Est End Date])}),
    #"Inserted Date Subtraction" = Table.AddColumn(#"Added Custom", "Remaining hours", each [Hours]/(Duration.Days([Est End Date] - [Est Stat Date])+1)),
    #"Removed Columns" = Table.RemoveColumns(#"Inserted Date Subtraction",{"Hours", "Est Stat Date", "Est End Date"}),
    #"Expanded Custom" = Table.ExpandListColumn(#"Removed Columns", "Custom"),
    #"Changed Type1" = Table.TransformColumnTypes(#"Expanded Custom",{{"Activity", Int64.Type}, {"Custom", type date}, {"Remaining hours", type number}})
in
    #"Changed Type1"

Hope this helps.

Ashish_Mathur_0-1742096851832.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

5 REPLIES 5
Ashish_Mathur
Super User
Super User

Hi,

This M code works

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Activity", Int64.Type}, {"Hours", Int64.Type}, {"Est Stat Date", type date}, {"Est End Date", type date}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each {Number.From([Est Stat Date])..Number.From([Est End Date])}),
    #"Inserted Date Subtraction" = Table.AddColumn(#"Added Custom", "Remaining hours", each [Hours]/(Duration.Days([Est End Date] - [Est Stat Date])+1)),
    #"Removed Columns" = Table.RemoveColumns(#"Inserted Date Subtraction",{"Hours", "Est Stat Date", "Est End Date"}),
    #"Expanded Custom" = Table.ExpandListColumn(#"Removed Columns", "Custom"),
    #"Changed Type1" = Table.TransformColumnTypes(#"Expanded Custom",{{"Activity", Int64.Type}, {"Custom", type date}, {"Remaining hours", type number}})
in
    #"Changed Type1"

Hope this helps.

Ashish_Mathur_0-1742096851832.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi @Ashish_Mathur thank you very much for the reply working all good.

You are welcome.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Deku
Super User
Super User

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTI00jfUNzQCsUxhLFMDpVidaCUjiLQRVNpI3xjKMgDKxwIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [activity = _t, start = _t, end = _t, hours = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"activity", Int64.Type}, {"start", type date}, {"end", type date}, {"hours", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Date", each List.Dates([start], Duration.Days([end] - [start]) + 1 , #duration(1, 0, 0, 0))),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Hours Per day", each [hours] / List.Count( [Date] )),
    #"Expanded Date" = Table.ExpandListColumn(#"Added Custom1", "Date"),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded Date",{"start", "end", "hours"})
in
    #"Removed Columns"

from 

Deku_0-1741859202661.png

To

Deku_1-1741859222030.png

 


Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!

Hi @Deku thank you very much for the help, working perfectly.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.