Forum Discussion

KW123's avatar
KW123
Helper V
3 years ago
Solved

Find differences between rows

Hi,  I have a data set:  Date Customer ID Transaction $ What I need to calculate 01/01/2023     1 $0.00 $0.00 01/01/2023     2 $0.00 $0.00 01/01/2023     3 $100 $100.00 ...
  • FreemanZ's avatar
    3 years ago

    hi KW123 

    try like:

    Diff = 
    VAR _customer = [CustomerID]
    VAR _date = [Date]
    VAR _table =
    FILTER(
        TableName,
        TableName[CustomerID] = _customer
            &&TableName[Date] < _date
        )
    )
    VAR _lastdate =
    MAXX( _table, TableName[Date])
    VAR _lasttransaction =
    MAXX(
        FILTER(
             _table,
             TableName[Date]=_lastdate
        ),
       TableName[Transaction]
    )
    RETURN
    [Transaction] - _lasttransaction