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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Jody
Frequent Visitor

Difference between columns in matrix

I have a matrix in Power BI desktop that looks like this.  Column headings 2018, 2019, 2020 represent years and the values are a "count" of PersonID (as opposed to sum).

COMPANY201820192020
A595570651
B12 
C17119
D455541531
E125106101
F286826782735

 

What I need is a column which calculates the difference between 2020 and 2019, ie. an excel formula of =2020-2019 with the result:

COMPANY201820192020DIFFERENCE
A59557065181
B12 -2
C17119-2
D455541531-10
E125106101-5
F28682678273557

 

and a growth rate, ie: =(2020-2019)/2019 shown as a percentage.  Is any of this possible in a matrix?

1 ACCEPTED SOLUTION
Anonymous
Not applicable

@Jody 

Yes this is possible. If you have the data already formatted nicely in a table (i.e. you're not taking counts yet), you want to make sure that the blank or null in the "2020" column is replaced with a zero so it does not mess up your calculations. You can do this by highlighting the "2020" column, right clicking, and then clicking "replace values..." to replace null with 0. If you are getting these values in your matrix with the count function from a different table, you just need to make sure you wrap each element of these measure equations in a COUNT, DISTINCTCOUNT, or COUNTX function depending if you are getting your values with a regular count, distinct count, count with conditions, etc.

Then you can just add a measure with an equation like this for your first request:

DIFFERENCE = VALUES(Table[2020]) - VALUES(Table[2019])

And like this for your second request:

GrowthRate = DIVIDE([DIFFERENCE], VALUES(Table[2019]))

Note again that you may need to replace the VALUES function with some variation of COUNT if your original table does not look like the table you've provided. This is what my final table looks like after applying those functions to your table:

Capture.PNG

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

@Jody 

Yes this is possible. If you have the data already formatted nicely in a table (i.e. you're not taking counts yet), you want to make sure that the blank or null in the "2020" column is replaced with a zero so it does not mess up your calculations. You can do this by highlighting the "2020" column, right clicking, and then clicking "replace values..." to replace null with 0. If you are getting these values in your matrix with the count function from a different table, you just need to make sure you wrap each element of these measure equations in a COUNT, DISTINCTCOUNT, or COUNTX function depending if you are getting your values with a regular count, distinct count, count with conditions, etc.

Then you can just add a measure with an equation like this for your first request:

DIFFERENCE = VALUES(Table[2020]) - VALUES(Table[2019])

And like this for your second request:

GrowthRate = DIVIDE([DIFFERENCE], VALUES(Table[2019]))

Note again that you may need to replace the VALUES function with some variation of COUNT if your original table does not look like the table you've provided. This is what my final table looks like after applying those functions to your table:

Capture.PNG

Anonymous
Not applicable

I have same problem, but I can't solve it.  I made matrix from table with values for places each year. I get Total in column to right but I need difference between column nr. 2 and 10 and ratio in next column.  I don't find solution for that.

 

My example in Matrix table

Place           2011       2012...........2019   Total(but I need difference)

East cost     10.605                  11.254    21.859 (649)

 

How do I solve this?

 

Best regards,

Jóhannes Finnur

Anonymous
Not applicable

@Jody 

I forgot to mention that to format the GrowthRate column as a percentage, you just need to click on the GrowthRate column in the Fields tab (on the right) and then on the Modeling tab on the top. Then you can select that you want your measure to be displayed as a percentage and how many decimal places you would like to see.

Hope this helps.

Thank you Emily, this has helped me enormously

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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