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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
lthuraga
New Member

Different Years and Different Months Percentage Difference Comparison

Screenshot (6).png

Hi,

I'm looking to calculate the percentage difference between two different months of two different years using a slicer. How should I procced with this as I have no found no solution to this. 

1 ACCEPTED SOLUTION
TomMartens
Super User
Super User

Hey @lthuraga ,

 

your requirement is simple but unfortunately not easy to implement. This is because there is no notion of a sequence or an ordered structure in the tabular model. For this reason, a DAX statement like the one below is more complex and relies on members of a column that can be ordered. Looking at your Month-Year members, I'm wondering about the expected result 😉

Nevertheless, the measure:

change between 2 dates = 
var selecteddates = calculatetable( VALUES( 'DimDate'[Datekey] ) , ALLSELECTED( 'DimDate' ) )
var sanityCheck = COUNTROWS( selecteddates )
return
IF( sanityCheck = 2
    , 
    var currentDate = CALCULATE( MAX( 'DimDate'[Datekey] ) )
    var DateFirst = MINX( selecteddates , [Datekey] )
    var DateSecond = MAXX( selecteddates , [Datekey] )
    var ValFirstDate = CALCULATE( [ms SalesQuantity] , 'DimDate'[Datekey] = DateFirst )
    var ValSecondDate = CALCULATE( [ms SalesQuantity] , 'DimDate'[Datekey] = DateSecond )
    var result = 
        IF( currentDate = DateSecond 
            , DIVIDE( ValSecondDate , ValFirstDate)
            , BLANK()
        )
    return result
    , BLANK()
)

A screenshot from a table visual:
image.png
Hopefully, this provides what you are looking for, at least provides you with some ideas on how you can tackle your challenge



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

View solution in original post

1 REPLY 1
TomMartens
Super User
Super User

Hey @lthuraga ,

 

your requirement is simple but unfortunately not easy to implement. This is because there is no notion of a sequence or an ordered structure in the tabular model. For this reason, a DAX statement like the one below is more complex and relies on members of a column that can be ordered. Looking at your Month-Year members, I'm wondering about the expected result 😉

Nevertheless, the measure:

change between 2 dates = 
var selecteddates = calculatetable( VALUES( 'DimDate'[Datekey] ) , ALLSELECTED( 'DimDate' ) )
var sanityCheck = COUNTROWS( selecteddates )
return
IF( sanityCheck = 2
    , 
    var currentDate = CALCULATE( MAX( 'DimDate'[Datekey] ) )
    var DateFirst = MINX( selecteddates , [Datekey] )
    var DateSecond = MAXX( selecteddates , [Datekey] )
    var ValFirstDate = CALCULATE( [ms SalesQuantity] , 'DimDate'[Datekey] = DateFirst )
    var ValSecondDate = CALCULATE( [ms SalesQuantity] , 'DimDate'[Datekey] = DateSecond )
    var result = 
        IF( currentDate = DateSecond 
            , DIVIDE( ValSecondDate , ValFirstDate)
            , BLANK()
        )
    return result
    , BLANK()
)

A screenshot from a table visual:
image.png
Hopefully, this provides what you are looking for, at least provides you with some ideas on how you can tackle your challenge



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.