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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
bernate
Helper II
Helper II

Add Variance Column to Matrix

Hello, I am looking to add a variance column to my matrix. The variance % calculation would be 1-(column2/column1).

 

Here is what my report currently looks like. I have a slicer that selects the columns in the matrix and I would need the variance to change based on the months selected.

bernate_1-1707782611266.png

Here is the result I want:

bernate_2-1707782741329.png

 

I have 14 attributes and they would change every year, so I can't hardcode the attribute names into my query. 

1 ACCEPTED SOLUTION
v-zhengdxu-msft
Community Support
Community Support

Hi @bernate 

Please try this:

First of all, I create a set of sample data:

vzhengdxumsft_0-1708416645013.png

Then create a new table with dax:

Table 2 = {1,2,3}

Then add a measure:

MEASURE =
VAR _newvalue =
    SELECTEDVALUE ( 'Table 2'[Value] )
VAR _columns =
    SWITCH (
        _newvalue,
        1, MAX ( 'Table'[Column1] ),
        2, MAX ( 'Table'[Column2] ),
        3, MAX ( 'Table'[Column3] )
    )
RETURN
    _columns

Then add a matrix and a slicer:

vzhengdxumsft_1-1708416786683.pngvzhengdxumsft_2-1708416798933.png

Then add a measure:

% =
VAR _maxvalue =
    MAXX ( ALLSELECTED ( 'Table 2' ), 'Table 2'[Value] )
VAR _minvalue =
    MINX ( ALLSELECTED ( 'Table 2' ), 'Table 2'[Value] )
RETURN
    IF (
        MAX ( 'Table 2'[Value] ) = _maxvalue
            && _maxvalue <> _minvalue,
        1
            - CALCULATE ( 'Table'[Measure], 'Table 2'[Value] = _maxvalue )
                / CALCULATE ( 'Table'[Measure], 'Table 2'[Value] = _minvalue )
    )

The result is as follow:

vzhengdxumsft_3-1708416988324.png

 

Best Regards

Zhengdong Xu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-zhengdxu-msft
Community Support
Community Support

Hi @bernate 

Please try this:

First of all, I create a set of sample data:

vzhengdxumsft_0-1708416645013.png

Then create a new table with dax:

Table 2 = {1,2,3}

Then add a measure:

MEASURE =
VAR _newvalue =
    SELECTEDVALUE ( 'Table 2'[Value] )
VAR _columns =
    SWITCH (
        _newvalue,
        1, MAX ( 'Table'[Column1] ),
        2, MAX ( 'Table'[Column2] ),
        3, MAX ( 'Table'[Column3] )
    )
RETURN
    _columns

Then add a matrix and a slicer:

vzhengdxumsft_1-1708416786683.pngvzhengdxumsft_2-1708416798933.png

Then add a measure:

% =
VAR _maxvalue =
    MAXX ( ALLSELECTED ( 'Table 2' ), 'Table 2'[Value] )
VAR _minvalue =
    MINX ( ALLSELECTED ( 'Table 2' ), 'Table 2'[Value] )
RETURN
    IF (
        MAX ( 'Table 2'[Value] ) = _maxvalue
            && _maxvalue <> _minvalue,
        1
            - CALCULATE ( 'Table'[Measure], 'Table 2'[Value] = _maxvalue )
                / CALCULATE ( 'Table'[Measure], 'Table 2'[Value] = _minvalue )
    )

The result is as follow:

vzhengdxumsft_3-1708416988324.png

 

Best Regards

Zhengdong Xu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@bernate , You switch the grand total with varinace

 

Measure =
var _min = minx(allselected(Date), Date[Date])
var _max = minx(allselected(Date), Date[Date])
return
if(isinscope(Date[Column month Year]) , [Measure], calculate([Meausre], filetr(Date, eomonth(Date[Date],0) = eomonth(_max,0))) -
calculate([Meausre], filetr(Date, eomonth(Date[Date],0) = eomonth(_min,0))) )

 

How to Switch Subtotal and Grand Total in Power BI | Power BI Tutorials| isinscope: https://youtu.be/smhIPw3OkKA

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.