Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

Find Previous Month and Year from datetime column

Hello all, 

 

I have an issue in finding Previous Month and Year. 

R_DateTime
01/07/2022 12:00:00 AM
01/08/2022 12:00:00 AM
01/09/2022 12:00:AM

 

I have a column called R_DateTime I have to find max month and year and Previous month and year from this column. 

Like CurrentMonth = Sep-2022 

        PreviousMonth = Aug-2022. 

The DAX should be dynamic if months get added later in future. 

 

Help would be much appreciated.

  • Anonymous ,

    Hope these two Measures solve your issue:

    CurrentMonthYear = FORMAT( MAX(R[R_DateTime]), "mmm-yyyy" )
    
    PreviousMonthYear = FORMAT(EOMONTH( MAX(R[R_DateTime]), -1 ), "mmm-yyyy" )

     

    Regards,

1 Reply

  • rsbin's avatar
    rsbin
    Icon for Community Champion rankCommunity Champion

    Anonymous ,

    Hope these two Measures solve your issue:

    CurrentMonthYear = FORMAT( MAX(R[R_DateTime]), "mmm-yyyy" )
    
    PreviousMonthYear = FORMAT(EOMONTH( MAX(R[R_DateTime]), -1 ), "mmm-yyyy" )

     

    Regards,