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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

Calculate variance between 2 rows in Matrix

Hello,

 

I am working on creating a matrix that is visual left to right vs top to bottom.  I am having trouble caluclating the varaince between the rows in the matrix.  My solution worked fine in the table visual but not in the matrix.  Any help would be greatly appreciated.  

 

My ideal would be replacing the total row in the matrix with a variance that subtracts 2021 info by month from 2020.  I know how to remove the total row but not replace with a variance.  

 

Thank you.

 

Table data displayed correctly. 

 

dkissane_0-1636170398410.png

 

Matrix currently displayed

 

dkissane_1-1636170442993.png

 

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

Hi, @Anonymous ;

You could create a measure like below:

Measure = IF(ISINSCOPE('Table'[Year]),SUM([Value]),CALCULATE(SUM([Value]),FILTER('Table',[Year]=2021))-CALCULATE(SUM([Value]),FILTER('Table',[Year]=2020)))

The final output is shown below:

vyalanwumsft_0-1636422604182.png

Best Regards,
Community Support Team_ Yalan Wu
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-yalanwu-msft
Community Support
Community Support

Hi, @Anonymous ;

You could create a measure like below:

Measure = IF(ISINSCOPE('Table'[Year]),SUM([Value]),CALCULATE(SUM([Value]),FILTER('Table',[Year]=2021))-CALCULATE(SUM([Value]),FILTER('Table',[Year]=2020)))

The final output is shown below:

vyalanwumsft_0-1636422604182.png

Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

ImkeF
Community Champion
Community Champion

Hi @Anonymous ,
you have to write 3 measures (amount for 2020, for 2021 and the difference) and place them all into the values-section of the matrix visual.
Then drag the month into the rows-section.

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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