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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
ZealandZu
Frequent Visitor

DateAdd but only week days

Hi All

 

Im having trouble visualising how i would carried out the following task. In Table 1 i have the task information like task number, the type, dates etc (the data is just representative and much much bigger)

 

Task#Task TypeStart DateTarget Completion DateStatus
123A1/3/2210/3/22Closed
124A3/4/2213/4/22Open
125B15/5/2210/6/22Open

 

Then in Table 2 i have Task type infomation with all the different task types, the phase description, the hours required a day, amount of days etc

 

Task TypePhaseDayDaily Hours requiredCumulative hrs
AStrip11010
ASurvey2818
ASurvey3826
ARepair41238

 

Now in reality Task A last 100s of days and task b is even more etc. 

 

So initially I merged table 1 with 2 in order to get something like this and added a Date column using Date.AddDays([Start Date],[#"Day-1]) (i made a day minus one column otherwise the first date would of been the 2/3/22)

 

Task#Task TypeStart DatePhaseDayDateHours
123A1/3/22Strip11/3/2210
123A1/3/22Survey22/3/228
123A1/3/22Survey33/3/228
123A1/3/22Repair44/3/2212
123A1/3/22Repair55/3/2212
123A1/3/22Build66/3/2210

The only problem with this though is that the 5th and 6th is on the weekend and no one would be in then to work. So Day 5 needs to Monday 7/3/22, Day 6 on the tues etc.

 

Now i do have a calendar table and that table does have whether the date is a working or non working date but i cant figure out how i add on a "Day" number to a date that excludes holidays and weekends.

 

Any ideas? Thanks

2 ACCEPTED SOLUTIONS
amitchandak
Super User
Super User

@ZealandZu , I have DAX solution

Traveling Across Workdays - What is next/previous Working day
https://community.powerbi.com/t5/Community-Blog/Travelling-Across-Workdays-Decoding-Date-and-Calenda...6

 

The column solution is given in the comment.

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

Anonymous
Not applicable

Hi  @ZealandZu ,

I created a sample pbix file(see attachment) for you, please check whether that is what you want. You can achieve it in Power Query Editor with below applied codes for Table1 query:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQyVtJRcgRiY31DfSMDIyMI0wDGds7JL05NUYrVAak1gao10TeGyZvoG8LZ/gWpeVCVpkCuExCb6huawKTNkIyFKI0FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Task#" = _t, #"Task Type" = _t, #"Start Date" = _t, #"Target Completion Date" = _t, Status = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Task#", Int64.Type}, {"Task Type", type text}, {"Start Date", type date}, {"Target Completion Date", type date}, {"Status", type text}}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Changed Type",{{"Start Date", Int64.Type}, {"Target Completion Date", Int64.Type}}),
    #"Added Custom1" = Table.AddColumn(#"Changed Type1", "Date", each {[Start Date]..[Target Completion Date]}),
    #"Expanded Date" = Table.ExpandListColumn(#"Added Custom1", "Date"),
    #"Changed Type2" = Table.TransformColumnTypes(#"Expanded Date",{{"Target Completion Date", type date}, {"Start Date", type date}, {"Date", type date}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type2", "Work Date", each if  Calendar[IsWorkday]{List.PositionOf(Calendar[Date],[Date])}=1 then Calendar[Date]{List.PositionOf(Calendar[Date],[Date])} else null),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Date"}),
    #"Filtered Rows" = Table.SelectRows(#"Removed Columns", each ([Work Date] <> null))
in
    #"Filtered Rows"

yingyinr_0-1660727635347.png

yingyinr_1-1660727665397.png

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi  @ZealandZu ,

I created a sample pbix file(see attachment) for you, please check whether that is what you want. You can achieve it in Power Query Editor with below applied codes for Table1 query:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQyVtJRcgRiY31DfSMDIyMI0wDGds7JL05NUYrVAak1gao10TeGyZvoG8LZ/gWpeVCVpkCuExCb6huawKTNkIyFKI0FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Task#" = _t, #"Task Type" = _t, #"Start Date" = _t, #"Target Completion Date" = _t, Status = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Task#", Int64.Type}, {"Task Type", type text}, {"Start Date", type date}, {"Target Completion Date", type date}, {"Status", type text}}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Changed Type",{{"Start Date", Int64.Type}, {"Target Completion Date", Int64.Type}}),
    #"Added Custom1" = Table.AddColumn(#"Changed Type1", "Date", each {[Start Date]..[Target Completion Date]}),
    #"Expanded Date" = Table.ExpandListColumn(#"Added Custom1", "Date"),
    #"Changed Type2" = Table.TransformColumnTypes(#"Expanded Date",{{"Target Completion Date", type date}, {"Start Date", type date}, {"Date", type date}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type2", "Work Date", each if  Calendar[IsWorkday]{List.PositionOf(Calendar[Date],[Date])}=1 then Calendar[Date]{List.PositionOf(Calendar[Date],[Date])} else null),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Date"}),
    #"Filtered Rows" = Table.SelectRows(#"Removed Columns", each ([Work Date] <> null))
in
    #"Filtered Rows"

yingyinr_0-1660727635347.png

yingyinr_1-1660727665397.png

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

amitchandak
Super User
Super User

@ZealandZu , I have DAX solution

Traveling Across Workdays - What is next/previous Working day
https://community.powerbi.com/t5/Community-Blog/Travelling-Across-Workdays-Decoding-Date-and-Calenda...6

 

The column solution is given in the comment.

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Apologies i may be doing something wrong, but when i click on your solution link, all im seeing is a load of images in an album that dont seem to relate to my issues. thanks

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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