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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
MikeChicago
Frequent Visitor

Calculate the difference between MIN MAX year in matrix

I have a slicer that the enduser can select multiple years with. I have a Matrix that shows the values by month for the year that the were selected from the slicer. 

 

How can I calculate the difference in a new measure in the matrix between the min selected yearly monthly value VS the MAX selected yearly montly value in the Matrix table?

5 REPLIES 5
MikeChicago
Frequent Visitor

I would like to subtract the top Month-Year coulmn from the bottom Month-Year. then put that result in bottom total group if possible. And if the user clicks the later year before the earlier year or three years that's ok it's his problem.

 

columntotalsProblem.png

 

 

@MikeChicago,

What is the current status of your issue? Could you please post expected result based on the sample data in your Matrix?

Regards,
Lydia

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
parry2k
Super User
Super User

Year Difference =

Datediff(MIN(Table1[Date]), Max(Table1[Date]), Year) + 1


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.

No I think I need DAX code that looks at the Matrix visual -> Finds the min/max year then claculates the difference between each month in the matrix. It possible some one could clikc 2017, 2012, 2016, 2015 so it would calculate the difference between 2017 and 2012 per month.

 

Year     January     Febuary

2017    20.00         10.00

2012      5.00           1.00

2016    18.00           8.00

2015    15.00           6.00

Diff      15.00           9.00

 

Do you have calendar table in data model?

 

Try this:

 

Diff Year = 
var minDate = Calculate(Min(Table[Date]), AllSelected(Table[Date]))
var maxDate= Calculate(Max(Table[Date]), AllSelected(Table[Date]))
return Datediff(minDate, maxDate, year)+1


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

Top Solution Authors