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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Get individual dates from start and end dates

I have a table WorkPerDay which tells me how many hours each person, should work per day.

id  |  personId  | date | hours

--------------------------

0  |  0  | 01.01.2022 | 8

1  |  0  | 02.01.2022 | 8

2  |  0  | 03.01.2022 | 8

3  |  1  | 01.01.2022 | 8

4  |  1  | 02.01.2022 | 8

5  |  1  | 03.01.2022 | 8

 

I also have a table Tasks which describes tasks that need doing, when they need doing, and how long they take to do

id | startDate | dueDate | totalHours

---------------------------------------

0 | 01.01.2022 | 08.01.2022 | 14

1 | 07.01.2022 | 08.01.2022 | 10

 

My goal is to create a chart where I can compare the total available hourse (based on the workPerDay table) and the hours of work required according to the Tasktable. The hour of work per day per task should be calculated by dividing the totalHours evenly between the startDate and dueDate. So for id 0 I required 2 hours of work on each of 01,02,03,04,05,06,07.01.2022.

 

My idea would be to blow up the task table into individual dates

id | taskId | Date | hours

---------------------------------------

0 | 0 | 01.01.2022 | 2

1 | 0 | 02.01.2022 | 2

2 | 0 | 03.01.2022 | 2

3 | 0 | 04.01.2022 | 2

4 | 0 | 05.01.2022 | 2

5 | 0 | 06.01.2022 | 2

6 | 0 | 07.01.2022 | 2

7 | 1 | 07.01.2022 | 10

 

Which I could then relate to my WorkPerDay table by date.

 

The problem is I don't know if this is right idea, and also not how to start doing this. Any help would be appreciated!

 

1 ACCEPTED SOLUTION
v-easonf-msft
Community Support
Community Support

Hi, @Anonymous 

Yes. It's an executable idea.

About how to blow up the task table into individual dates, you can try following steps in PowerQuery.

1.add custom columns to calculate the interval days and the working hours required per day

=Duration.TotalDays([dueDate]-[startDate])

1.png

=[totalHours]/[Custom]

2.png

2.add another list to contain all dates in this period (List.Dates )

=List.Dates([startDate],[Custom],#duration(1, 0, 0, 0))

3.png

3.Expend the list -> remove the column you do not want -> rename the new column->add index column

4.png

5.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlDSUTIyMDLSNTAEImSOBZBjaKIUqxOthCJujqHIQCk2FgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, startDate = _t, dueDate = _t, totalHours = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"startDate", type date}, {"dueDate", type date}, {"totalHours", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Duration.TotalDays([dueDate]-[startDate])),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Hours", each [totalHours]/[Custom]),
    #"Added Custom2" = Table.AddColumn(#"Added Custom1", "Custom.1", each List.Dates([startDate],[Custom],#duration(1, 0, 0, 0))),
    #"Expanded Custom.1" = Table.ExpandListColumn(#"Added Custom2", "Custom.1"),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded Custom.1",{"startDate", "dueDate", "totalHours", "Custom"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Custom.1", "Date"}, {"ID", "TaskID"}}),
    #"Added Index" = Table.AddIndexColumn(#"Renamed Columns", "Index", 0, 1, Int64.Type),
    #"Reordered Columns" = Table.ReorderColumns(#"Added Index",{"Index", "TaskID", "Date", "Hours"})
in
    #"Reordered Columns"

Please check my sample file for more details.

Best Regards,
Community Support Team _ Eason

View solution in original post

2 REPLIES 2
v-easonf-msft
Community Support
Community Support

Hi, @Anonymous 

Yes. It's an executable idea.

About how to blow up the task table into individual dates, you can try following steps in PowerQuery.

1.add custom columns to calculate the interval days and the working hours required per day

=Duration.TotalDays([dueDate]-[startDate])

1.png

=[totalHours]/[Custom]

2.png

2.add another list to contain all dates in this period (List.Dates )

=List.Dates([startDate],[Custom],#duration(1, 0, 0, 0))

3.png

3.Expend the list -> remove the column you do not want -> rename the new column->add index column

4.png

5.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlDSUTIyMDLSNTAEImSOBZBjaKIUqxOthCJujqHIQCk2FgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, startDate = _t, dueDate = _t, totalHours = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"startDate", type date}, {"dueDate", type date}, {"totalHours", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Duration.TotalDays([dueDate]-[startDate])),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Hours", each [totalHours]/[Custom]),
    #"Added Custom2" = Table.AddColumn(#"Added Custom1", "Custom.1", each List.Dates([startDate],[Custom],#duration(1, 0, 0, 0))),
    #"Expanded Custom.1" = Table.ExpandListColumn(#"Added Custom2", "Custom.1"),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded Custom.1",{"startDate", "dueDate", "totalHours", "Custom"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Custom.1", "Date"}, {"ID", "TaskID"}}),
    #"Added Index" = Table.AddIndexColumn(#"Renamed Columns", "Index", 0, 1, Int64.Type),
    #"Reordered Columns" = Table.ReorderColumns(#"Added Index",{"Index", "TaskID", "Date", "Hours"})
in
    #"Reordered Columns"

Please check my sample file for more details.

Best Regards,
Community Support Team _ Eason

amitchandak
Super User
Super User

@Anonymous , the first table you can join with date table for second, you can skip join with date table and use measure using the blog

 

https://community.powerbi.com/t5/Community-Blog/How-to-divide-distribute-values-between-start-date-or-end-date/ba-p/1503785

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors