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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

Comparing Difference in Columns of A Matrix (Dynamic Column Values)

Hi guys


I've got a matrix that uses 2 columns from 2 tables - column 'Year' from table 'Programme' and column 'Type' from 'PersonTypes'. In the rows of the matrix I have Type and in the columns I have Year, with a count of the Type in the values. It looks along the lines of this:

 

Type       2018   2019   2020

Type1        3        2        5

Type2        1        2        5

Type3        0        2        6

Type4        8        1        5

 

What I want to do is add a calculated column on the end that will calculate the difference in percentage between a selected column and the previous years column (where the current year is selected by default). So possibly something like this (if column 2020 was selected):

 

Type       2018   2019   2020    Difference

Type1        3        2        5            150

Type2        1        2        5            150

Type3        0        2        6            200

Type4        8        1        5            400


I have seen posts on other threads for queries similar to this but they seem to be hard coded for the the columns needed for comparison. The number of columns I have is dynamic and will increase as data is added for new years into the Programme table (2021,2022 etc), and I would preferably want the columns for comparison to default to any new years automatically for comparison. Is this possible and how exactly can I do it?

 

Any help or advice welcome please. Thank you

2 REPLIES 2
lbendlin
Super User
Super User

this basically boils down to the "second best"  problem.  You can use variables or TREATAS to resolve that

 

With variables it would be something like this

 

Var a = currentyear

Var b = currentyearvalue

var c = calculate(value, lastnonblank(year), year< a )

Return (b-c)/c*100

stevedep
Memorable Member
Memorable Member

Hi,,

Can you explain the difference column with a few examples?

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

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 community update carousel

Fabric Community Update - June 2025

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