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
lloydchughes
New Member

Create Task EndDate but exclude weekends

Hi,

 

I'm trying to create an End Date for proejct task from StartDate + BuildTimeDays  (Which is just a whole number)

 

I want to exclude the weekends from the calculation and be able to display them in the gantt chart visual.

 

Example -

 

Task 1 - StartDate 01/01/2023, BuildTimeDays = 15 meaning EndDate would be 06/01/2023 normally but 01/01/2023, 11/01/2023 and 07/01/2023 being a Saturday EndDate would be 16/01/2023 but really it should be Thursday 21/01/2023.

 

It seems this should be pretty easy in a custom column calculation but i'm rather new to PowerBi.

 

Any assistance would be great thank you.

 

 

 

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

If you do not have a calendar dim table, please check the below picture and the attached pbix file.

It is for creating a calculated column.

 

Untitled.png

 

Enddate CC =
VAR _mindate =
    MIN ( Data[StartDate] )
VAR _maxdate =
    DATE ( YEAR ( MAX ( Data[StartDate] ) ) + 1, 12, 31 )
VAR _calendartableexcludingsatsun =
    FILTER (
        ADDCOLUMNS (
            CALENDAR ( _mindate, _maxdate ),
            "@dayname", FORMAT ( [Date], "ddd" )
        ),
        NOT ( [@dayname] IN { "Sat", "Sun" } )
    )
VAR _count =
    ADDCOLUMNS (
        _calendartableexcludingsatsun,
        "@count",
            COUNTROWS (
                FILTER (
                    _calendartableexcludingsatsun,
                    [Date] >= Data[StartDate]
                        && [Date] <= EARLIER ( [Date] )
                )
            )
    )
RETURN
    SUMMARIZE ( FILTER ( _count, [@count] = Data[BuildTimeDays] ), [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


View solution in original post

3 REPLIES 3
lloydchughes
New Member

This solution works well thank you. 

 

How would you do it if you were using a Date Table?

 

Cheers,

 

Lloyd

Hi,

Thank you for your message.

If there was a calendar table, I can save some lines in the formula to create virtual calendar table, and then I can refer to the actual calendar table in the formula.

Please share your sample pbix file's link, and then I can try to come up with another solution.

Thank you.

 

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


Jihwan_Kim
Super User
Super User

Hi,

If you do not have a calendar dim table, please check the below picture and the attached pbix file.

It is for creating a calculated column.

 

Untitled.png

 

Enddate CC =
VAR _mindate =
    MIN ( Data[StartDate] )
VAR _maxdate =
    DATE ( YEAR ( MAX ( Data[StartDate] ) ) + 1, 12, 31 )
VAR _calendartableexcludingsatsun =
    FILTER (
        ADDCOLUMNS (
            CALENDAR ( _mindate, _maxdate ),
            "@dayname", FORMAT ( [Date], "ddd" )
        ),
        NOT ( [@dayname] IN { "Sat", "Sun" } )
    )
VAR _count =
    ADDCOLUMNS (
        _calendartableexcludingsatsun,
        "@count",
            COUNTROWS (
                FILTER (
                    _calendartableexcludingsatsun,
                    [Date] >= Data[StartDate]
                        && [Date] <= EARLIER ( [Date] )
                )
            )
    )
RETURN
    SUMMARIZE ( FILTER ( _count, [@count] = Data[BuildTimeDays] ), [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


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.