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

calculate number of working days between 2 dates

Hi all, 

 

I'm new in Dax and Power BI. 

 

I try to compare the due date of an invoice with a custom date the users will manually select. 

 

It works with to today date in automatique "int(DATE(YEAR(NOW());MONTH(NOW());DAY(NOW())) - 'DATE_DUDDAT')" 

 

Someone having an idea ? 

 

 

1 ACCEPTED SOLUTION
v-jiascu-msft
Employee
Employee

Hi @Ilrale,

 

Firstly, you need a date table that is with no relationship with your current table. Because the dates will be filtered out if you use the dates in the invoice table or in the table having relationship with invoice table. You can try it out in this file.

1. A new date table if you don't have one.

Calendar =
ADDCOLUMNS (
    CALENDAR ( DATE ( 2017, 1, 1 ), DATE ( 2018, 2, 28 ) ),
    "IsWeekend", IF ( WEEKDAY ( [Date], 2 ) IN { 6, 7 }, 1, 0 )
)

2. Create a measure.

WorkdaysCount =
DATEDIFF ( MIN ( 'Table'[Date] ), MIN ( 'Calendar'[Date] ), DAY ) + 1
    - SUMX (
        FILTER (
            ALL ( 'Calendar' ),
            'Calendar'[Date] >= MIN ( 'Table'[Date] )
                && 'Calendar'[Date] <= MIN ( 'Calendar'[Date] )
        ),
        'Calendar'[IsWeekend]
    )

calculate_number_of_working_days_between_2_dates

 

 

Best Regards,

Dale

Community Support Team _ Dale
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-jiascu-msft
Employee
Employee

Hi @Ilrale,

 

Firstly, you need a date table that is with no relationship with your current table. Because the dates will be filtered out if you use the dates in the invoice table or in the table having relationship with invoice table. You can try it out in this file.

1. A new date table if you don't have one.

Calendar =
ADDCOLUMNS (
    CALENDAR ( DATE ( 2017, 1, 1 ), DATE ( 2018, 2, 28 ) ),
    "IsWeekend", IF ( WEEKDAY ( [Date], 2 ) IN { 6, 7 }, 1, 0 )
)

2. Create a measure.

WorkdaysCount =
DATEDIFF ( MIN ( 'Table'[Date] ), MIN ( 'Calendar'[Date] ), DAY ) + 1
    - SUMX (
        FILTER (
            ALL ( 'Calendar' ),
            'Calendar'[Date] >= MIN ( 'Table'[Date] )
                && 'Calendar'[Date] <= MIN ( 'Calendar'[Date] )
        ),
        'Calendar'[IsWeekend]
    )

calculate_number_of_working_days_between_2_dates

 

 

Best Regards,

Dale

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

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.

Top Solution Authors