The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredCompete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.
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]
)