Forum Discussion

Uka's avatar
Uka
Frequent Visitor
2 years ago
Solved

Calculate the difference in values between previous dates

Hello,

 

Please can you help me to return the difference between two values within some given dates as below;

So, I would like to substract the previous date value from the current one ie ((Eng FullTime) on the 13/10/2023) - ((Eng FullTime) on the 06/10/2023)

 

The (Eng Fulltime) is a measure that was calclulated as below; 

Eng FullTime = CALCULATE(DISTINCTCOUNT('ENG SOB'[Employee]), FILTER('ENG SOB', 'ENG SOB'[Groups] = "Engineer"))

Many thanks in advance!
  • Uka's avatar
    Uka
    2 years ago

    Hi Greg_Deckler ,

     

    Many thanks for your assistance!

     

    I have now figured it out using the following;

    Weekly Difference =
    Var _selecteddate = VALUES('Date Friday Only'[Date])
    var _maxdate = MAXX(_selecteddate, 'Date Friday Only'[Date])
    var _value2 = CALCULATE([Eng FullTime], 'Date Friday Only'[Date] = _maxdate)
    var _value3 = CALCULATE([Eng FullTime], 'Date Friday Only'[Date] = _maxdate -7)

    Return
    _value2 - _value3

    _value3 has -7 because the dates occur every 7 days, thus returns the date for the previous week
     
    Thanks

5 Replies

    • Uka's avatar
      Uka
      Frequent Visitor

      Hello Greg_Deckler ,

       

      The solution did not work for me as I got a wired result as below;

      Below is the code that I used;

      #Result =
        VAR __Current = CALCULATE(DISTINCTCOUNT('ENG SOB'[Employee]), FILTER('ENG SOB', 'ENG SOB'[Groups] = "Engineer"))
        VAR __PreviousDate = MAXX(FILTER('ENG SOB','ENG SOB'[Operational Date] < EARLIER('ENG SOB'[Operational Date])),[Operational Date])
        VAR __Previous = MAXX(FILTER('ENG SOB',[Operational Date]=__PreviousDate),[Eng FullTime])
      RETURN
        __Current - __PreviousDate

      Greg_Deckler Please can you offer another method?