March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
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
Solved! Go to Solution.
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.
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.
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.
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.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
23 | |
16 | |
12 | |
9 | |
7 |
User | Count |
---|---|
38 | |
32 | |
28 | |
12 | |
11 |