How to subtract Debit column value from previous Balance column value.

I want to create a simple expense tracker app but I am not able to figure out the formula with IF expression.

If value of column 'Transaction type=‘Debit’ then it should get subtracted from previous Balance column value. How to apply formula so that I get the correct Balance amount.

  1. Have a column en each row where you calculate the key of the last row. Name it for example: previousKey and make it of type Ref pointing to the same table.
  2. Your current balance would be calculated with something like:
    ( whatever ) - [previousKey].[balance]