Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

EOMONTH working days calculation

I have a measure to subtract the total number of days in a month e.g. 31 - absence.

 

Measure =
VAR _lastday =
DAY (
EOMONTH (
DATE ( LEFT ( MAX ( 'DimDate'[Month Year] ), 4 ), VALUE ( RIGHT ( MAX ( 'DimDate'[Month Year] ), 2 ) ), 1 ),
0
)
)
RETURN
IF ( ISBLANK ( [AbsentByDay] ), BLANK (), _lastday ) - [AbsentByDay]
 
Is there a way to only include working days in this calculation e.g. 22 working days in month - absence?
 
e.g. NOT WEEKDAY( 'DimDate'[Date] ) IN { 1,7 }
 
File attached:
  • Fowmy's avatar
    Fowmy
    5 years ago

    Anonymous 

    The DimDate table has a column, Working Day, I used that as that is your basis for other measures:

    Please check now:

     

    Measure 3 = 
    
    VAR _Month = 
        EOMONTH (
            DATE ( LEFT ( MAX ( 'DimDate'[Month Year] ), 4 ), VALUE ( RIGHT ( MAX ( 'DimDate'[Month Year] ), 2 ) ), 1 ),
            0
        )
    VAR _lastday= 
    COUNTROWS(
        FILTER(
            DimDate,
            DimDate[Date] >= EDATE(_Month , -1)+1 && DimDate[Date] <= _Month && DimDate[WorkingDays] = TRUE())
    )    
    
    RETURN
    
     IF ( ISBLANK ( [AbsentByDay] ), BLANK (), _lastday ) - [AbsentByDay]

     

     

    ________________________

    If my answer was helpful, please consider Accept it as the solution to help the other members find it

    Click on the Thumbs-Up icon if you like this reply 🙂

    YouTube  LinkedIn

4 Replies

  • Anonymous 

    I have modified the formula to include only workdays, I consider weekday 1 and 7 as weekend, you can change if you need.

    Measure = 
    
    VAR _Month = 
        EOMONTH (
            DATE ( LEFT ( MAX ( 'DimDate'[Month Year] ), 4 ), VALUE ( RIGHT ( MAX ( 'DimDate'[Month Year] ), 2 ) ), 1 ),
            0
        )
    
    VAR _lastday= 
    COUNTROWS(
        FILTER(
            CALENDAR( EDATE(_Month , -1)+1 , _Month ),
            NOT( WEEKDAY( [Date] ) IN { 1,7 })
        )
    )
    
    RETURN
     IF ( ISBLANK ( [AbsentByDay] ), BLANK (), _lastday ) - [AbsentByDay]

     

    ________________________

    If my answer was helpful, please consider Accept it as the solution to help the other members find it

    Click on the Thumbs-Up icon if you like this reply 🙂

    YouTube  LinkedIn

      • Fowmy's avatar
        Fowmy
        Super User

        Anonymous 

        The DimDate table has a column, Working Day, I used that as that is your basis for other measures:

        Please check now:

         

        Measure 3 = 
        
        VAR _Month = 
            EOMONTH (
                DATE ( LEFT ( MAX ( 'DimDate'[Month Year] ), 4 ), VALUE ( RIGHT ( MAX ( 'DimDate'[Month Year] ), 2 ) ), 1 ),
                0
            )
        VAR _lastday= 
        COUNTROWS(
            FILTER(
                DimDate,
                DimDate[Date] >= EDATE(_Month , -1)+1 && DimDate[Date] <= _Month && DimDate[WorkingDays] = TRUE())
        )    
        
        RETURN
        
         IF ( ISBLANK ( [AbsentByDay] ), BLANK (), _lastday ) - [AbsentByDay]

         

         

        ________________________

        If my answer was helpful, please consider Accept it as the solution to help the other members find it

        Click on the Thumbs-Up icon if you like this reply 🙂

        YouTube  LinkedIn