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
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
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.

Top Solution Authors