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

Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers. Get Fabric certified for FREE! 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
Community Champion
Community Champion

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
Community Champion
Community Champion

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
PBIApril_Carousel

Power BI Monthly Update - April 2025

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

Notebook Gallery Carousel1

NEW! Community Notebooks Gallery

Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.

April2025 Carousel

Fabric Community Update - April 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors