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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
MTrullàs
Helper III
Helper III

working days

 Hello,


I have a problem with this metric. I need to count the working days between the two dates. In some moments, the metric works perfectly, but in other situations, it does not work like in the example.


Anybody know why?


Thank you for your comments.

 

MTrulls_1-1654753241712.png

 

 

 

 

 

 

 

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

Hi @MTrullàs 
It is difficult to verify how columns are evaluated within the filter context without having the data in front of your eyes. However, I would follow a totally different approach. I would create my own calendar table. The only thing is that I don't know what are you expecting to see if either of the start/end dates is blank? I just return zero.

Transporte Campa =
VAR StartDay =
    MAX ( HIFA[Ch35 (WERK-AUS) Ist] )
VAR EndDay =
    MAX ( HIFA[Ch38 (DEP-EIN) Ist] )
RETURN
    IF (
        ISBLANK ( StartDay ) || ISBLANK ( EndDay ),
        0,
        VAR DatesTable =
            CALENDAR ( StartDay, EndDay - 1 )
        VAR DatesAndWeekDays =
            ADDCOLUMNS ( DatesTable, "@WeekDay", WEEKDAY ( [Date], 2 ) )
        VAR WorkDaysTable =
            FILTER ( DatesAndWeekDays, NOT ( [@WeekDay] IN { 6, 7 } ) )
        RETURN
            COUNTROWS ( WorkDaysTable )
    )

View solution in original post

2 REPLIES 2
MTrullàs
Helper III
Helper III

Thank you very much for the answer!

tamerj1
Super User
Super User

Hi @MTrullàs 
It is difficult to verify how columns are evaluated within the filter context without having the data in front of your eyes. However, I would follow a totally different approach. I would create my own calendar table. The only thing is that I don't know what are you expecting to see if either of the start/end dates is blank? I just return zero.

Transporte Campa =
VAR StartDay =
    MAX ( HIFA[Ch35 (WERK-AUS) Ist] )
VAR EndDay =
    MAX ( HIFA[Ch38 (DEP-EIN) Ist] )
RETURN
    IF (
        ISBLANK ( StartDay ) || ISBLANK ( EndDay ),
        0,
        VAR DatesTable =
            CALENDAR ( StartDay, EndDay - 1 )
        VAR DatesAndWeekDays =
            ADDCOLUMNS ( DatesTable, "@WeekDay", WEEKDAY ( [Date], 2 ) )
        VAR WorkDaysTable =
            FILTER ( DatesAndWeekDays, NOT ( [@WeekDay] IN { 6, 7 } ) )
        RETURN
            COUNTROWS ( WorkDaysTable )
    )

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

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.