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

Calculating number of days absent per month excluding weekends

Hi 

 

I'm trying to calculate the number of workforce absent days per month based on a start and end date and which takes into account absence spanning across a number of months.

 

I've come across the following code which is working perfectly for the number of calendar days, however, i would like to discount weekends and struggling on how to do it?

 

Any help greatly appreciated!

 

Calculated_Sick_days =

VAR MinDate = MIN ( Date_table[Date] )
VAR MaxDate = MAX ( Date_table[Date])
RETURN
   SUMX (
        Absence,
        VAR startDate =
            MAX ( Absence[Absence Start Date],MinDate)
        VAR endDate =
            IF (
                ISBLANK ( Absence[Absence End Date]),
                MaxDate,
                MIN ( Absence[Absence End Date], MaxDate ))
        RETURN
            (IF (
                endDate >= MaxDate,
                IF ( endDate >= startDate, DATEDIFF ( startDate, endDate + 1, DAY ) ),
                IF ( endDate >= startDate, DATEDIFF ( startDate, endDate + 1, DAY ) )
            )
    ))
3 REPLIES 3
ppm1
Solution Sage
Solution Sage

You can use the NETWORKDAYS function for that. Assuming the In date is when the person returns, here is an example measure.

 

WorkDaysOut = SUMX(T7, NETWORKDAYS(T7[Out], T7[In]-1))
 
ppm1_0-1674478809891.png

 

Pat

Microsoft Employee
Anonymous
Not applicable

Thanks Pat, but this doesn't work for people with an open ended absence. i.e. some people haven't returned to work yet and have a blank entry in the Absence end date.

 

I also want to show the the number of absences per month in a simple line chart by month and your measure just gives me a constant line

Please try this version that uses TODAY() for any rows w/o a return date yet.

WorkDaysOut2 =
SUMX (
    T7,
    VAR maxdate =
        COALESCE ( T7[In], TODAY () )
    RETURN
        NETWORKDAYS ( T7[Out], maxdate - 1 )
)

 

Pat

 

Microsoft Employee

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.