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
Ninna
Frequent Visitor

Calculating difference between columns in matrix view based on filter

Hi,

 

let's say I have matrix table visual with months in rows and countries in columns, and in filter I choose which countries I want to compare.

I need to get column (red in picture) that will calculate % difference between selected countries and that depends on what country I choose in filter. 

 

Ninna_1-1677058566576.png

 

 

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

Hi @Ninna 
You can activate and rename the total column then place the following measure in the matrix instead of the original measure

ResultMeasure =
VAR NormalValue = [OriginalMeasure]
VAR SelectedCountries =
    ALLSELECTED ( 'Table'[Country] )
VAR Country1 =
    MAXX ( SelectedCountries, 'Table'[Country] )
VAR Country2 =
    MINX ( SelectedCountries, 'Table'[Country] )
VAR Country1Value =
    CALCULATE ( [OriginalMeasure], 'Table'[Country] = Country1 )
VAR Country2Value =
    CALCULATE ( [OriginalMeasure], 'Table'[Country] = Country2 )
VAR Difference = Country2Value - Country1Value
RETURN
    IF ( HASONEVALUE ( 'Table'[Country] ), NormalValue, Difference )

View solution in original post

2 REPLIES 2
tamerj1
Super User
Super User

Hi @Ninna 
You can activate and rename the total column then place the following measure in the matrix instead of the original measure

ResultMeasure =
VAR NormalValue = [OriginalMeasure]
VAR SelectedCountries =
    ALLSELECTED ( 'Table'[Country] )
VAR Country1 =
    MAXX ( SelectedCountries, 'Table'[Country] )
VAR Country2 =
    MINX ( SelectedCountries, 'Table'[Country] )
VAR Country1Value =
    CALCULATE ( [OriginalMeasure], 'Table'[Country] = Country1 )
VAR Country2Value =
    CALCULATE ( [OriginalMeasure], 'Table'[Country] = Country2 )
VAR Difference = Country2Value - Country1Value
RETURN
    IF ( HASONEVALUE ( 'Table'[Country] ), NormalValue, Difference )
Ninna
Frequent Visitor

Great, that is it. Thanks 🙂

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!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.