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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

Dynamic Date Field

I have a coworker that created a date field in a dashboard (see below).  Based on today's date the field would read 2021-6.  My concern is how will this field appear once we reach January 2022.  How do I change this dax formula so that when we are in January 2022 the field shows December 2021?    

 

 

month p1 Display = YEAR([month p0 DATE]) & "-" & Month([month p0 DATE]) - 1
1 ACCEPTED SOLUTION
m3tr01d
Continued Contributor
Continued Contributor

Hello @Anonymous,

You're right, the code for your month Display wouldn't return the correct result for January 2022.
You can create a measure with this code :

VAR _LastMonth = EOMONTH( TODAY(), -1)
VAR _Formatted = FORMAT( _LastMonth, "YYYY-MM")
RETURN _Formatted


Example : 
If today's date is 2022-01-06, 
The first variable will return 2021-12-31
The second variable will format the result to show 2021-12

You can also change the format to  "MMM YYYY" if you want.

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

This worked! Thank you for your help!

m3tr01d
Continued Contributor
Continued Contributor

Hello @Anonymous,

You're right, the code for your month Display wouldn't return the correct result for January 2022.
You can create a measure with this code :

VAR _LastMonth = EOMONTH( TODAY(), -1)
VAR _Formatted = FORMAT( _LastMonth, "YYYY-MM")
RETURN _Formatted


Example : 
If today's date is 2022-01-06, 
The first variable will return 2021-12-31
The second variable will format the result to show 2021-12

You can also change the format to  "MMM YYYY" if you want.

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.