Forum Discussion
MikeChicago
8 years agoFrequent 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 diffe...
parry2k
Super User
8 years agoYear Difference = Datediff(MIN(Table1[Date]), Max(Table1[Date]), Year) + 1
MikeChicago
8 years agoFrequent Visitor
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
- parry2k8 years ago
Super User
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