Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
I want to show a visual which return month over month change for last 12 months. Can someone provide the dax code for it
Solved! Go to Solution.
Hi @Anonymous,
Did you mean the expression should apply to the last 12-month ranges based on the latest date and show the month-over-month difference in these ranges?
For your requirement, you can add variables to extract value from the table and use the if statement to check the current date and the last date and skip the calculation in the not match date ranges.
Sample measure:
formula =
VAR currDate =
MAX ( Table[Date] )
VAR prevDate =
DATE ( YEAR ( currDate ), MONTH ( currDate ) - 1, DAY ( currDate ) )
VAR cMonth =
CALCULATE (
SUM ( Table[Amount] ),
FILTER (
ALLSELECTED ( Table ),
YEAR ( [Date] ) = currDate
&& MONTH ( [Date] ) = MONTH ( currDate )
)
)
VAR pMonth =
CALCULATE (
SUM ( Table[Amount] ),
FILTER (
ALLSELECTED ( Table ),
YEAR ( [Date] ) = prevDate
&& MONTH ( [Date] ) = MONTH ( prevDate )
)
)
VAR _lastDate =
MAXX ( ALLSELECTED ( Table ), [Date] )
VAR _LYDate =
DATE ( YEAR ( _lastDate ) - 1, MONTH ( _lastDate ), DAY ( _lastDate ) )
RETURN
IF (
currDate >= _LYDate
&& currDate <= _lastDate,
DIVIDE ( cMonth - pMonth, pMonth )
)
Regards,
Xiaoxin Sheng
@Anonymous , With help from a date tbale used in formula and visual
a measure
Rolling 12 = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date ],MAX(Sales[Sales Date]),-12,MONTH))
Rolling Months Formula: https://youtu.be/GS5O4G81fww
Thanks for the reply. I want to calculate month over month change and show it for last 12 months. I want to calculate the change percent in current month value as compared to previous month value and return that change for last 12 months
Hi @Anonymous,
Did you mean the expression should apply to the last 12-month ranges based on the latest date and show the month-over-month difference in these ranges?
For your requirement, you can add variables to extract value from the table and use the if statement to check the current date and the last date and skip the calculation in the not match date ranges.
Sample measure:
formula =
VAR currDate =
MAX ( Table[Date] )
VAR prevDate =
DATE ( YEAR ( currDate ), MONTH ( currDate ) - 1, DAY ( currDate ) )
VAR cMonth =
CALCULATE (
SUM ( Table[Amount] ),
FILTER (
ALLSELECTED ( Table ),
YEAR ( [Date] ) = currDate
&& MONTH ( [Date] ) = MONTH ( currDate )
)
)
VAR pMonth =
CALCULATE (
SUM ( Table[Amount] ),
FILTER (
ALLSELECTED ( Table ),
YEAR ( [Date] ) = prevDate
&& MONTH ( [Date] ) = MONTH ( prevDate )
)
)
VAR _lastDate =
MAXX ( ALLSELECTED ( Table ), [Date] )
VAR _LYDate =
DATE ( YEAR ( _lastDate ) - 1, MONTH ( _lastDate ), DAY ( _lastDate ) )
RETURN
IF (
currDate >= _LYDate
&& currDate <= _lastDate,
DIVIDE ( cMonth - pMonth, pMonth )
)
Regards,
Xiaoxin Sheng
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
57 | |
55 | |
55 | |
37 | |
30 |
User | Count |
---|---|
78 | |
66 | |
45 | |
44 | |
40 |