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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
alexw94
Helper I
Helper I

How to get a Month & Year name for previous 2 months?

I am wanting to have 3 visual cards that shows the previous MONTH YEAR and month before previous. What DAX meausre do I need to obtain this please? This is just simply the month and year name on a card. 

 

I so far have the current month.

April 2023 and the measure is   CurrentMonth = Format(Now(),"MMMM YYYY")

 

But now I need:

March 2023

February 2023

 

Any ideas on how I can achieve this please? Thanks

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

One of ways to achieve this is to write measures like below.

Please check the below picture and the attached pbix file.

If you do not want to create a virtual calendar table inside the measure, then try using only two dax functions, those are EOMONTH DAX function and FORMAT DAX Function.

 

Jihwan_Kim_0-1682085109399.png

 

 

Prev month year: =
VAR _today =
    TODAY ()
VAR _prevendofmonth =
    EOMONTH ( _today, -1 )
VAR _prevprevendofmonth =
    EOMONTH ( _today, -2 )
VAR _prevyear =
    YEAR ( _today ) - 1
VAR _currentyear =
    YEAR ( _today )
VAR _calendar =
    ADDCOLUMNS (
        CALENDAR ( DATE ( _prevyear, 1, 1 ), DATE ( _currentyear, 12, 31 ) ),
        "@Month Year", FORMAT ( [Date], "mmmm yyyy" ),
        "@Month Year sort", EOMONTH ( [Date], 0 )
    )
VAR _monthyearcalendar =
    SUMMARIZE ( _calendar, [@Month Year], [@Month Year sort] )
RETURN
    MAXX (
        FILTER ( _monthyearcalendar, [@Month Year sort] = _prevendofmonth ),
        [@Month Year]
    )

 

PrevPrev month year: = 
VAR _today =
    TODAY ()
VAR _prevendofmonth =
    EOMONTH ( _today, -1 )
VAR _prevprevendofmonth =
    EOMONTH ( _today, -2 )
VAR _prevyear =
    YEAR ( _today ) - 1
VAR _currentyear =
    YEAR ( _today )
VAR _calendar =
    ADDCOLUMNS (
        CALENDAR ( DATE ( _prevyear, 1, 1 ), DATE ( _currentyear, 12, 31 ) ),
        "@Month Year", FORMAT ( [Date], "mmmm yyyy" ),
        "@Month Year sort", EOMONTH ( [Date], 0 )
    )
VAR _monthyearcalendar =
    SUMMARIZE ( _calendar, [@Month Year], [@Month Year sort] )
RETURN
    MAXX (
        FILTER ( _monthyearcalendar, [@Month Year sort] = _prevprevendofmonth ),
        [@Month Year]
    )

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

1 REPLY 1
Jihwan_Kim
Super User
Super User

Hi,

One of ways to achieve this is to write measures like below.

Please check the below picture and the attached pbix file.

If you do not want to create a virtual calendar table inside the measure, then try using only two dax functions, those are EOMONTH DAX function and FORMAT DAX Function.

 

Jihwan_Kim_0-1682085109399.png

 

 

Prev month year: =
VAR _today =
    TODAY ()
VAR _prevendofmonth =
    EOMONTH ( _today, -1 )
VAR _prevprevendofmonth =
    EOMONTH ( _today, -2 )
VAR _prevyear =
    YEAR ( _today ) - 1
VAR _currentyear =
    YEAR ( _today )
VAR _calendar =
    ADDCOLUMNS (
        CALENDAR ( DATE ( _prevyear, 1, 1 ), DATE ( _currentyear, 12, 31 ) ),
        "@Month Year", FORMAT ( [Date], "mmmm yyyy" ),
        "@Month Year sort", EOMONTH ( [Date], 0 )
    )
VAR _monthyearcalendar =
    SUMMARIZE ( _calendar, [@Month Year], [@Month Year sort] )
RETURN
    MAXX (
        FILTER ( _monthyearcalendar, [@Month Year sort] = _prevendofmonth ),
        [@Month Year]
    )

 

PrevPrev month year: = 
VAR _today =
    TODAY ()
VAR _prevendofmonth =
    EOMONTH ( _today, -1 )
VAR _prevprevendofmonth =
    EOMONTH ( _today, -2 )
VAR _prevyear =
    YEAR ( _today ) - 1
VAR _currentyear =
    YEAR ( _today )
VAR _calendar =
    ADDCOLUMNS (
        CALENDAR ( DATE ( _prevyear, 1, 1 ), DATE ( _currentyear, 12, 31 ) ),
        "@Month Year", FORMAT ( [Date], "mmmm yyyy" ),
        "@Month Year sort", EOMONTH ( [Date], 0 )
    )
VAR _monthyearcalendar =
    SUMMARIZE ( _calendar, [@Month Year], [@Month Year sort] )
RETURN
    MAXX (
        FILTER ( _monthyearcalendar, [@Month Year sort] = _prevprevendofmonth ),
        [@Month Year]
    )

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

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