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
Anonymous
Not applicable

Comparison of last working day for previous months

Struggling to write the DAX to calculate the below, any help would be much appreciated. 

 

I currently have a set of data which i'd like to track the change between last working days for the previous 2 months. I'm able to calculate the differences however I'm struggling to return the last working days for previous months.

These should return 29th Oct & 30th November

Untitled.png

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

Hi, @Anonymous ;

You could create a measure such as:

Current Date1 =
VAR _eomon =
    EOMONTH ( MAX ( [Date] ), -1 )
RETURN CALCULATE (MAX ( [Date] ),
        FILTER (ALL ( carlendar ),
            WEEKDAY ( [Date], 2 )IN { 1, 2, 3, 4, 5 }
                    && YEAR ( [Date] ) = YEAR ( _eomon )
                    && MONTH ( [Date] ) = MONTH ( _eomon )))
Previous Date1 = 
VAR _eomon =
    EOMONTH ( MAX ( [Date] ), -2 )
RETURN CALCULATE ( MAX ( [Date] ),
        FILTER (ALL ( carlendar ),
            WEEKDAY ( [Date], 2 ) IN { 1, 2, 3, 4, 5 }
                    && YEAR ( [Date] ) = YEAR ( _eomon )
                    && MONTH ( [Date] ) = MONTH ( _eomon )))

The final output is shown below:

vyalanwumsft_0-1639372055646.png

Best Regards,
Community Support Team_ Yalan Wu
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

4 REPLIES 4
v-yalanwu-msft
Community Support
Community Support

Hi, @Anonymous ;

You could create a measure such as:

Current Date1 =
VAR _eomon =
    EOMONTH ( MAX ( [Date] ), -1 )
RETURN CALCULATE (MAX ( [Date] ),
        FILTER (ALL ( carlendar ),
            WEEKDAY ( [Date], 2 )IN { 1, 2, 3, 4, 5 }
                    && YEAR ( [Date] ) = YEAR ( _eomon )
                    && MONTH ( [Date] ) = MONTH ( _eomon )))
Previous Date1 = 
VAR _eomon =
    EOMONTH ( MAX ( [Date] ), -2 )
RETURN CALCULATE ( MAX ( [Date] ),
        FILTER (ALL ( carlendar ),
            WEEKDAY ( [Date], 2 ) IN { 1, 2, 3, 4, 5 }
                    && YEAR ( [Date] ) = YEAR ( _eomon )
                    && MONTH ( [Date] ) = MONTH ( _eomon )))

The final output is shown below:

vyalanwumsft_0-1639372055646.png

Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Hi Amitchandak, 

Thanks for the response. 

 

Here is a screenshot of my date table. 

 

In essence I want to display a comparison of the INC Count only for the last working day of the previous two months.

 

e.g as today is December 8th, I'd need to display the dates for 30 Nov & 29 Oct. If either of these dates would fall on the weekend then it would return the date on friday

 

I was was trying to write two measures. 


Current Date = should return 30th Nov

Previous Date = should return 29th Oct

Untitled2.PNG

Hi @Anonymous 

Try this:

Measure =
VAR _T =
    TODAY()
VAR _FT =
    DATE( YEAR( _T ), MONTH( _T ), 1 )
VAR _1FD =
    DATE( YEAR( _FT - 1 ), MONTH( _FT - 1 ), 1 )
VAR _2FD =
    DATE( YEAR( _1FD - 1 ), MONTH( _1FD - 1 ), 1 )
VAR _1ED =
    CALCULATE(
        MAX( Date[Date] ),
        FILTER(
            ALL( Date ),
            Date[Year] = YEAR( _1FD )
                && Date[Month] = MONTH( _1FD )
                && Date[is Weekend] = 0
        )
    )
VAR _2ED =
    CALCULATE(
        MAX( Date[Date] ),
        FILTER(
            ALL( Date ),
            Date[Year] = YEAR( _2FD )
                && Date[Month] = MONTH( _2FD )
                && Date[is Weekend] = 0
        )
    )
RETURN
    CALCULATE(
        SUM( Table[Value] ),
        FILTER( ALL( 'Date' ), Date[Date] = _1ED || Date[Date] = _2ED )
    )

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
LinkedIn: 
www.linkedin.com/in/vahid-dm/

 

 

 

amitchandak
Super User
Super User

@Anonymous ,

A measure like

 

calculate(lastnonblankvalue('Date'[Date], sum(Table[Value]) ) , filter(allselected('Date'), Date[Month Year] = max( Date[Month Year] )))

 

Assumed you are using date table

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :radacad sqlbi My Video Series Appreciate your Kudos.

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.