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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
ayush_sinha
Helper I
Helper I

month over month change for Rolling 12 months

I want to show a visual which return month over month change for last 12 months. Can someone provide the dax code for it

1 ACCEPTED SOLUTION

Hi @ayush_sinha,

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

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

3 REPLIES 3
amitchandak
Super User
Super User

@ayush_sinha , 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 @ayush_sinha,

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

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.