Forum Discussion

MikeChicago's avatar
MikeChicago
Frequent Visitor
8 years ago

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

  • Year Difference =
    
    Datediff(MIN(Table1[Date]), Max(Table1[Date]), Year) + 1
    • MikeChicago's avatar
      MikeChicago
      Frequent 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

       

      • parry2k's avatar
        parry2k
        Icon for Super User rankSuper 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
  • MikeChicago's avatar
    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.

     

     

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      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