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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

DATEDIFF without weekends

Hi guys,

 

I had a different post in which I asked help with my formule for the days between two dates using four different dates. That is fixed... well not completely..  

The formula below does indeed work correct. However, I only want the working days. Can someone explaine how to fix this?

 

min date = MIN('date'[Date])

max date = MAX('date'[Date])

range = 
VAR s =
    MAX ( 'Table'[start date] )
VAR e =
    MAX ( 'Table'[end date] )
RETURN
    IF([max date]>=s&&[max date]<=e,IF([min date]>=s,"midlle","left"),IF([max date]>e,IF([min date]<=e,"right","na"))

whole days =
SWITCH (
    [range],
    "midlle", DATEDIFF ( [min date], [max date], DAY ) + 1,
    "left", DATEDIFF ( MAX ( 'Table'[start date] ), [max date], DAY ) + 1,
    "right", DATEDIFF ( [min date], MAX ( 'Table'[end date] ), DAY ) + 1,
    0
)

Thanks!

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

Hi @Anonymous 

Based on the formula above, i work out the days of weekend in these periods.

Capture1.JPG

weekend =
VAR right_weekend =
    CALCULATE (
        COUNT ( 'date'[Date] ),
        FILTER (
            'date',
            [Date] >= [min date]
                && [Date] <= MAX ( 'Table'[end date] )
                && WEEKDAY ( [Date], 2 ) >= 6
        )
    )
VAR left_weekend =
    CALCULATE (
        COUNT ( 'date'[Date] ),
        FILTER (
            'date',
            [Date] >= MAX ( 'Table'[start date] )
                && [Date] <= [max date]
                && WEEKDAY ( [Date], 2 ) >= 6
        )
    )
VAR midlle_weekend =
    CALCULATE (
        COUNT ( 'date'[Date] ),
        FILTER (
            'date',
            [Date] >= [min date]
                && [Date] <= [max date]
                && WEEKDAY ( [Date], 2 ) >= 6
        )
    )
RETURN
    SWITCH (
        [range],
        "right", right_weekend,
        "left", left_weekend,
        "midlle", midlle_weekend,
        0
    )
final days = [whole days]-[weekend]
Best Regards
Maggie
Community Support Team _ Maggie Li
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

1 REPLY 1
v-juanli-msft
Community Support
Community Support

Hi @Anonymous 

Based on the formula above, i work out the days of weekend in these periods.

Capture1.JPG

weekend =
VAR right_weekend =
    CALCULATE (
        COUNT ( 'date'[Date] ),
        FILTER (
            'date',
            [Date] >= [min date]
                && [Date] <= MAX ( 'Table'[end date] )
                && WEEKDAY ( [Date], 2 ) >= 6
        )
    )
VAR left_weekend =
    CALCULATE (
        COUNT ( 'date'[Date] ),
        FILTER (
            'date',
            [Date] >= MAX ( 'Table'[start date] )
                && [Date] <= [max date]
                && WEEKDAY ( [Date], 2 ) >= 6
        )
    )
VAR midlle_weekend =
    CALCULATE (
        COUNT ( 'date'[Date] ),
        FILTER (
            'date',
            [Date] >= [min date]
                && [Date] <= [max date]
                && WEEKDAY ( [Date], 2 ) >= 6
        )
    )
RETURN
    SWITCH (
        [range],
        "right", right_weekend,
        "left", left_weekend,
        "midlle", midlle_weekend,
        0
    )
final days = [whole days]-[weekend]
Best Regards
Maggie
Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.