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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anon2020
Helper I
Helper I

Dynamic Column Difference in Matrix

I have a matrix set up with Total sales by FY by Producyt Code. I am unable to find a formula that accurately depicts the difference betyween the two selected years that the user chooses from a filter. I have tried several variations and looked through multiple forums only to find solutions that are not dynamic. Any help is greatly appreciated!!!

 

Here is what I have so far 

Anon2020_0-1755658295039.png

 

1 ACCEPTED SOLUTION
danextian
Super User
Super User

Hi @Anon2020 

It seems to me that you're trying to show the min and max selected years and a column for the difference, if so try this DAX measure

Min Max Difference = 
VAR _minYr =
    MINX ( ALLSELECTED ( CalendarTable ), CalendarTable[Year] )
VAR _maxYr =
    MAXX ( ALLSELECTED ( CalendarTable ), CalendarTable[Year] )
VAR _years = { _minYr, _maxYr }
VAR _minYrValue =
    SUMX (
        FILTER ( ALLSELECTED ( CalendarTable[Year] ), CalendarTable[Year] = _minYr ),
        [Total Sales]
    )
VAR _maxYrValue =
    SUMX (
        FILTER ( ALLSELECTED ( CalendarTable[Year] ), CalendarTable[Year] = _maxYr ),
        [Total Sales]
    )
RETURN
    SWITCH (
        TRUE (),
        NOT ( HASONEVALUE ( CalendarTable[Year] ) ), _maxYrValue - _minYrValue,
        SELECTEDVALUE ( CalendarTable[Year] )
            IN _years && HASONEVALUE ( CalendarTable[Year] ), [Total Sales]
    )

danextian_0-1755668877645.png

Please see the attached pbix.

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

View solution in original post

6 REPLIES 6
v-sdhruv
Community Support
Community Support

Hi @Anon2020 ,
Since we didnt hear back from you, we will be closing this thread.
If you have any issues, please feel free to raise a separate ticket and we will be happy to assist you.

Thank You

v-sdhruv
Community Support
Community Support

Hi @Anon2020 ,

Just wanted to check if you got a chance to review the suggestions provided and whether that helped you resolve your query?

Thank You

v-sdhruv
Community Support
Community Support

Hi @Anon2020 ,

Just wanted to check if you got a chance to review the suggestions provided and whether that helped you resolve your query?

Thank You @pankajnamekar25  , @danextian  and @Shahid12523  for your valuable inputs to the query.

Shahid12523
Community Champion
Community Champion

Use this DAX measure to calculate the dynamic difference between two selected FYs


Sales Difference Between FYs =
VAR SelectedFYs = VALUES('Date'[FinYear])
VAR FY1 = MIN(SelectedFYs)
VAR FY2 = MAX(SelectedFYs)
RETURN
IF(
COUNTROWS(SelectedFYs) = 2,
CALCULATE([Total Sales], 'Date'[FinYear] = FY2) -
CALCULATE([Total Sales], 'Date'[FinYear] = FY1)
)

 

Replace 'Date'[FinYear] with your Fiscal Year column
Replace [Total Sales] with your measure

Shahed Shaikh
danextian
Super User
Super User

Hi @Anon2020 

It seems to me that you're trying to show the min and max selected years and a column for the difference, if so try this DAX measure

Min Max Difference = 
VAR _minYr =
    MINX ( ALLSELECTED ( CalendarTable ), CalendarTable[Year] )
VAR _maxYr =
    MAXX ( ALLSELECTED ( CalendarTable ), CalendarTable[Year] )
VAR _years = { _minYr, _maxYr }
VAR _minYrValue =
    SUMX (
        FILTER ( ALLSELECTED ( CalendarTable[Year] ), CalendarTable[Year] = _minYr ),
        [Total Sales]
    )
VAR _maxYrValue =
    SUMX (
        FILTER ( ALLSELECTED ( CalendarTable[Year] ), CalendarTable[Year] = _maxYr ),
        [Total Sales]
    )
RETURN
    SWITCH (
        TRUE (),
        NOT ( HASONEVALUE ( CalendarTable[Year] ) ), _maxYrValue - _minYrValue,
        SELECTEDVALUE ( CalendarTable[Year] )
            IN _years && HASONEVALUE ( CalendarTable[Year] ), [Total Sales]
    )

danextian_0-1755668877645.png

Please see the attached pbix.

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
pankajnamekar25
Super User
Super User

Hello @Anon2020 

 

 

Base Measure

 

Total Sales =
SUM ( Sales[SalesAmount] )

 

Selected Years

 

Selected Year Min =
MIN ( 'Date'[FiscalYear] )

Selected Year Max =
MAX ( 'Date'[FiscalYear] )

 

Sales for Min Year

 

Sales Min Year =
CALCULATE (
[Total Sales],
'Date'[FiscalYear] = [Selected Year Min]
)

 

Sales for Max Year

 

Sales Max Year =
CALCULATE (
[Total Sales],
'Date'[FiscalYear] = [Selected Year Max]
)

 

Year Difference (Final Measure)

 

Year Difference =
IF (
DISTINCTCOUNT ( 'Date'[FiscalYear] ) = 2,
[Sales Max Year] - [Sales Min Year],
BLANK()
)


I

If my response helped you, please consider clicking
Accept as Solution and giving it a Like 👍 – it helps others in the community too.


Thanks,


Connect with me on:

LinkedIn

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 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.