cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
rachaelwalker
Resolver II
Resolver II

Add business days to a date based on a value from another column

I want to add business days to a date based on the value in another column. I successfully added calendar days in power query using Date.AddDays but I need it to add using business days 

 

I have two related tables: Project and Calendar. I am trying to solve for Target Date adding business days only. See sample data and expected results below.

 

[Target Date] = [PO Date] + [SLA] 

 

Project Table

Project IDDate Created*PO DateSLATarget Date
12345/19/20225/20/202255/27/2022
12355/21/20225/23/202255/30/2022
12365/21/20225/25/202276/3/2022
12375/24/20225/31/2022106/14/2022
12386/1/20226/2/202256/8/2022
12396/3/20236/3/202256/10/2022

 

Calendar Table

Date*Business Day
5/20/2022Friday
5/21/2022Saturday
5/22/2022Sunday
5/23/2022Monday
5/24/2022Tuesday
5/25/2022Wednesday
5/26/2022Thursday
5/27/2022Friday
5/28/2022Saturday
5/29/2022Sunday
5/30/2022Monday
5/31/2022Tuesday
6/1/2022Wednesday
6/2/2022Thursday
6/3/2022Friday
6/4/2022Saturday

* relationship

 

I am following this video https://www.youtube.com/watch?v=2HkBbqxBzF0 but I have not been successful. 

 

 

2 ACCEPTED SOLUTIONS
tamerj1
Super User
Super User

Hi @rachaelwalker 

please try

Target Date =
VAR PODate = [PO Date]
VAR N = [SLA] + 1
VAR Dates =
FILTER (
ALL ( 'Calendar'[Date] ),
'Calendar'[Date] >= PODate
&& NOT ( WEEKDAY ( 'Calendar'[Date], 2 ) IN { 6, 7 } )
)
VAR FirstNDates =
TOPN ( N, Dates, 'Calendar'[Date], ASC )
RETURN
MAXX ( FirstDates, 'Calendar'[Date] )

View solution in original post

Thank you! I was able to get it to work using similar way you have outlined!

 

Target Date =
VAR StartDate = 'Project'[PO Date]
VAR NextWorkingDates =
    FILTER (
        ALL ( 'Calendar' ),
        'Calendar'[Date] > StartDate
            && 'Calendar'[DayofBusiness] = TRUE
    )
VAR WorkingDaysPlusSLA =
    TOPN (
        'Project'[SLA],
        NextWorkingDates,
        'Calendar'[Date], ASC
    )
VAR Result =
    MAXX ( WorkingDaysPlusSLA, 'Calendar'[Date] )
RETURN
    Result

View solution in original post

4 REPLIES 4
tamerj1
Super User
Super User

Hi @rachaelwalker 

please try

Target Date =
VAR PODate = [PO Date]
VAR N = [SLA] + 1
VAR Dates =
FILTER (
ALL ( 'Calendar'[Date] ),
'Calendar'[Date] >= PODate
&& NOT ( WEEKDAY ( 'Calendar'[Date], 2 ) IN { 6, 7 } )
)
VAR FirstNDates =
TOPN ( N, Dates, 'Calendar'[Date], ASC )
RETURN
MAXX ( FirstDates, 'Calendar'[Date] )

Thank you! I was able to get it to work using similar way you have outlined!

 

Target Date =
VAR StartDate = 'Project'[PO Date]
VAR NextWorkingDates =
    FILTER (
        ALL ( 'Calendar' ),
        'Calendar'[Date] > StartDate
            && 'Calendar'[DayofBusiness] = TRUE
    )
VAR WorkingDaysPlusSLA =
    TOPN (
        'Project'[SLA],
        NextWorkingDates,
        'Calendar'[Date], ASC
    )
VAR Result =
    MAXX ( WorkingDaysPlusSLA, 'Calendar'[Date] )
RETURN
    Result

@rachaelwalker 

Just be careful if [SLA] = 0 days, TOPN will generate an error

The SLA value should never be 0 but thank you for calling that out for awareness. I will double double check that! Thank you!

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

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

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors