Forum Discussion

carlochecchia's avatar
carlochecchia
Advocate I
5 years ago
Solved

Calculate Difference Based on Last Entry (Date and Time Column)

Hi there,   I have the following table and would like to get some help in regards to how to calculate the column called 'Change' I would like to create a Dax Measure that calculates the difference...
  • carlochecchia's avatar
    5 years ago

    In case it was tough to understand the data, here it goes again

    DateTime NetProducts Change
    22/07/2021 20:30                 1.780.022 --
    22/07/2021 20:35                 1.780.022 0
    22/07/2021 21:00                 1.780.037 -15
    22/07/2021 21:04                 1.780.037 0
    22/07/2021 21:05                 1.780.037 0
    22/07/2021 21:15                 1.780.037 0
    22/07/2021 21:19                 1.780.037 0
    22/07/2021 21:42                 1.780.049 -12
    22/07/2021 21:42                 1.780.049 0
    22/07/2021 21:56                 1.780.049 0
    22/07/2021 22:02                 1.780.049 0
    22/07/2021 22:12                 1.780.049 0
    22/07/2021 22:46                 1.780.064 -15
  • sevenhills's avatar
    sevenhills
    5 years ago
    Change2 = 
    var _cValDT = SELECTEDVALUE('Table'[DateTime])
    var _cValStore = SELECTEDVALUE('Table'[Store])
    var _cVal = SELECTEDVALUE('Table'[NetProducts])
    var _pValDT = Maxx(Filter( ALLSELECTED('Table'),  'Table'[DateTime] < _cValDT && 'Table'[Store] = _cValStore), 'Table'[DateTime])
    var _pValDT_Val = Maxx(Filter( ALLSELECTED('Table'),  'Table'[DateTime] = _pValDT && 'Table'[Store] = _cValStore), 'Table'[NetProducts])
    Return IF ( ISBLANK(_pValDT_Val), "--", ( _cVal - _pValDT_Val))

     

    Mark this one as answer to the solution. (I saw you marked your question post as answer)