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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
Anonymous
Not applicable

Difference between two columns in Matrix

Hi guys,

 

Can someone help me with the following:

 

I need to create 5 more columns which respectively will be the difference between 2020 and 2019.

 

I'm quite sure I'll need some kind of custom measure for it, just don't know which.

 

jcerq_1-1611678071146.png

 

Thank you in advance.

 

1 ACCEPTED SOLUTION
parry2k
Super User
Super User

@Anonymous assuming you have date dimension in your model, if yes, good, otherwise add one and then add following measure:

 

Difference from PY = 
VAR __prevYear = CALCULATE ( SUM ( Table[Sales] ), PREVIOUSYEAR ( DateTable[Date] ) )
RETURN
SUM ( Table[Sales] ) - __prevYear

 

if you already have a measure, then use that instead of SUM ( Table[Sales] )

 

Check my latest blog post Compare Budgeted Scenarios vs. Actuals I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

2 REPLIES 2
v-shex-msft
Community Support
Community Support

Hi @Anonymous,

I think you can create a calculation table with all column category that you used on the snapshot.
Then you can use it on the column fields of the matrix and write a measure with switch function to check current row content and category to return special expression results.

Regards,
Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
parry2k
Super User
Super User

@Anonymous assuming you have date dimension in your model, if yes, good, otherwise add one and then add following measure:

 

Difference from PY = 
VAR __prevYear = CALCULATE ( SUM ( Table[Sales] ), PREVIOUSYEAR ( DateTable[Date] ) )
RETURN
SUM ( Table[Sales] ) - __prevYear

 

if you already have a measure, then use that instead of SUM ( Table[Sales] )

 

Check my latest blog post Compare Budgeted Scenarios vs. Actuals I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

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