Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
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]
)
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]
)
User | Count |
---|---|
25 | |
11 | |
8 | |
7 | |
7 |
User | Count |
---|---|
24 | |
13 | |
12 | |
10 | |
6 |