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

Difference of selected columns in matrix

Hello together,

 

I have the following problem: I have a matrix with grades as rows and dates (months-year) as columns. The value is the number of grades for the corresponding month. The table looks similar to the following:

 

GradeJan 2020Feb 2020Mar 2020Apr 2020
11233
23344
34425
45616

 

What I want to achieve is the following: If I select the columns Mar 2020 & Jan 2020, I want to see how the number of grades has changed, for example, for grade 1 I want to see the result of this calculation: 3-1=2, for grade 2 I want to see 4-3=1, etc.

 

Ideally, a new column would automatically occur after the column Mar 2020 and is labeled as "Difference" or something similar. Is something like that somehow possible?

 

Thank you in advance:)

 

4 REPLIES 4
amitchandak
Super User
Super User

@Anonymous , if this you raw format, Unpivot it, Get month in row. You can have date from the month and use time intelligence

 

date ="01-" & right([month],3) &"-" & left([month],4) //mark as date column

 

example - with date table

MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD('Date'[Date]))
last MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-1,MONTH)))

diff = [MTD Sales]-[last MTD Sales]

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

Thank you for your answer @amitchandak . I want this to be dynamic so that the user can select the specific columns where he wants to see the difference. Is your solution dynamic? I guess, in your solutions, I have to specify the specific columns beforehand.

Anonymous
Not applicable

Hi @Anonymous,

If you do unpivot columns on your date field to convert them as attribute and value, they will expand your records with different these date values.

Unpivot columns (Power Query) 
If you use these fields to create a matrix and write a measure formula based on current row contents, it can be dynamic changes based on your selections.

Using the SELECTEDVALUE function in DAX 
Regards,

Xiaoxin Sheng

Greg_Deckler
Community Champion
Community Champion

@Anonymous Yes, I would have to dig up the various threads on this, there are multiple but it comes down to using ALL and then FILTER to filter down to the rows you want. Would need sample source data to be more specific. Sorry, having trouble following, can you post sample data as text and expected output. Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.

 

I'll try to dig up the threads.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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