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
SirTim
Frequent Visitor

How to determine the end date excluding weekends/holidays where I have the start date and duration

Hi Community,

 

I am wanting to determine the end date of a task excluding weekends and holidays. I have the start date and duration. I have trawled the forum and have not been able to find a solution.

 

I have three tables: Tasks, Date, Public Holiday. The result I am looking for is if a task should start on a Friday and has a duration of 3 days then the end date should be Tuesday of the following week. For the life o me I cannot seem to finds a solution that works. Any help would be greatly appreciated.Screenshot 2021-09-11 102934.png

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

Hi @SirTim ,

I created a sample pbix file(see attachment) for you, please check whether that is what you want.

1. Create two calculated columns as in Dates table as below to get the flag of isHoliday and Weekday

Note: If you have already created these two columns, you can skip this step and go to the next step directly: create the calculated column EndDate.

isHoliday = 
VAR _holidaydate =
    CALCULATE (
        MAX ( 'PublicHolidays'[Date] ),
        FILTER ( 'PublicHolidays', 'PublicHolidays'[Date] = 'Dates'[Date] )
    )
RETURN
    IF ( ISBLANK ( _holidaydate ), 0, 1 )
isWorkingday = IF('Dates'[isHoliday]=0&&'Dates'[Weekday]<6,1,0)

yingyinr_1-1631600599427.png

2. Create a calculated column in Tasks table to get the EndDate

EndDate = 
VAR _tab =
    ADDCOLUMNS (
        'Dates',
        "@count",
            CALCULATE (
                COUNT ( 'Dates'[Date] ),
                FILTER (
                    'Dates',
                    'Dates'[isHoliday] = 0
                        && 'Dates'[Weekday] < 6
                        && 'Dates'[Date] >= 'Tasks'[StartDate]
                        && 'Dates'[Date] <= EARLIER ( 'Dates'[Date] )
                )
            )
    )
RETURN
    CALCULATE (
        MIN ( 'Dates'[Date] ),
        FILTER (
            'Dates',
            MAXX ( FILTER ( _tab, [Date] = EARLIER ( 'Dates'[Date] ) ), [@count] ) = 'Tasks'[Duration]
        )
    )

yingyinr_0-1631600503241.png

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

6 REPLIES 6
v-yiruan-msft
Community Support
Community Support

Hi @SirTim ,

I created a sample pbix file(see attachment) for you, please check whether that is what you want.

1. Create two calculated columns as in Dates table as below to get the flag of isHoliday and Weekday

Note: If you have already created these two columns, you can skip this step and go to the next step directly: create the calculated column EndDate.

isHoliday = 
VAR _holidaydate =
    CALCULATE (
        MAX ( 'PublicHolidays'[Date] ),
        FILTER ( 'PublicHolidays', 'PublicHolidays'[Date] = 'Dates'[Date] )
    )
RETURN
    IF ( ISBLANK ( _holidaydate ), 0, 1 )
isWorkingday = IF('Dates'[isHoliday]=0&&'Dates'[Weekday]<6,1,0)

yingyinr_1-1631600599427.png

2. Create a calculated column in Tasks table to get the EndDate

EndDate = 
VAR _tab =
    ADDCOLUMNS (
        'Dates',
        "@count",
            CALCULATE (
                COUNT ( 'Dates'[Date] ),
                FILTER (
                    'Dates',
                    'Dates'[isHoliday] = 0
                        && 'Dates'[Weekday] < 6
                        && 'Dates'[Date] >= 'Tasks'[StartDate]
                        && 'Dates'[Date] <= EARLIER ( 'Dates'[Date] )
                )
            )
    )
RETURN
    CALCULATE (
        MIN ( 'Dates'[Date] ),
        FILTER (
            'Dates',
            MAXX ( FILTER ( _tab, [Date] = EARLIER ( 'Dates'[Date] ) ), [@count] ) = 'Tasks'[Duration]
        )
    )

yingyinr_0-1631600503241.png

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@v-yiruan-msft If I have a task that ends on a Friday, it is showing that task a completing on a Sunday. How do I resolve this. it should show the task as being complete on the Firday.

mahoneypat
Employee
Employee

You can modify the approach described in this video to get your result.

(1) Power BI - Tales from the Front #03 - Due Date From Working Days - YouTube

 

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Jihwan_Kim
Super User
Super User

Hi,

My sample only has weekends, and I do not have your public holiday information.

However, I think the concept of approaching the problem is quite similar.

Please check the link down below, that is the sample of the pbix file.

 

Picture2.png

 

Enddate excluding weekend count : =
VAR _startdate =
MAX ( Tasks[Startdate] )
VAR _duration = [Duration measure :]
VAR _calendarexcludeweekend =
FILTER (
'Calendar',
'Calendar'[DayOfWeek] <> 0
&& 'Calendar'[DayOfWeek] <> 6
&& 'Calendar'[Date] >= _startdate
)
VAR _rankexcludeweekend =
FILTER (
ADDCOLUMNS (
FILTER (
'Calendar',
'Calendar'[DayOfWeek] <> 0
&& 'Calendar'[DayOfWeek] <> 6
&& 'Calendar'[Date] >= _startdate
),
"@rank", RANKX ( _calendarexcludeweekend, CALCULATE ( MAX ( 'Calendar'[Date] ) ),, ASC )
),
[@rank] = _duration
)
RETURN
MAXX ( _rankexcludeweekend, 'Calendar'[Date] )
 
 
 
 

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


Hi Jihwan,

 

Thanks for the prompt response.

 

Unfortunately I don't get the same response as you: I have duration (dev days captured), however, no end date is calculated. Any suggestions?

Screenshot 2021-09-11 215155.png

Hi,

Thank you for your feedback.

Sorry that I cannot know where is the problem without seeing how you wrote a measure in what data model. Showing only the screenshot does not help me to understand.

That is why I created the sample by myself and shared it.

I am not sure how your data model looks like. I am not sure how you applied my measure to your data model.

Sharing your sample pbix file will help people to look into it to come up with a more accurate solution.

Thanks.

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


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.