I’ve been struggling a couple of days with the calculation of walletbalances in Power BI.
We are working with customers who have a so called “Wallet”.
As an attachment you will find dummy data of 5 customers.

In the first worksheet you will find all the data:
Timeperiod = Year/Month
ClientId = ClientID
Balance_start_period = The startbalance of the wallet
Revenue - Purchases, normally “Balance Out” but it is possible to have a “Balance In” if the purchase has failed.
Payments = Payments (= Balance In)
Cashback = In certain circumstances a customer receives a cashback (=Balance In).
Balance_end_period = The endbalance of the wallet

Worksheet 2 t/m 6: calculations in Excel of the different customers.

Additional information for Cashback:

Revenue Cashback: if Revenue < 0 then Revenue else 0.
Endbalance Cashback: If (startbalance CB + Revenue Cashback + Cashback) < 0 then 0 else (Startbalance CB + Revenue Cashback + Cashback)

Extra:
It is possible to have a wallet < 0, those are Accounts Receivable Customers.

Can someone help me to do the Excel-calculations in Power BI?

The calculation of the endbalances of the Cashbacks;

The overall endbalance contains the amount of Cashbacks (point 1) and an amount of “non-Cashback”.
I would like to see the overall amount that is separated between these 2 items.

For example ClientID 699, 2018 September gives 0,30, in October there are no transactions, so the endbalance needs still to be 0,30 and not 0,00. Can you help me with the formula for calculating the correct endbalance?

The way you can do this is running a cummulative total on the Total Cashback Balance Change.

I just have a question for you, I see in your excel file that for the Cashback Balance for the client 699 you are not taking the whole data set, correct?

Because I have run the cummulative total and I got a balance for the whole data of -170.42, and doing the cummulative totals after July, 2018 I got the balance you want.

Attached is the PBIX file with the measures Cashback Balance and Cashback Balance > July/2018

In January 2015 the Total Revenue is - 9,06. The startbalance was 0, revenue cashback - 9,06 and Cashback 0.
0 - 9,06 + 0 = - 9,06 is less then 0 so cashback is 0.

On July 2018 is the calculation (see rule 2) 0 + 0 + 3,63 is more than 0 so the endbalance is 3,63.
Calculation August 2018: 3,63 - 3,62 + 2,41 = endbalance 2,42
Calculation September 2018: 2,42 - 2,12 + 0 = endbalance 0,30
Calculation October 2018: 0,30 + 0 + 0 = endbalance 0,30 and the endbalances for November and December 2018 and January 2019 should also be 0,30.

I’m taking the whole dataset from the beginning and not only a subset from after July 2018.

Maybe you can understand my challenge now and maybe you can help me to solve this challenge.

Furthermore, when I change the context to all customers, it isn’t calculating the Total endbalance for all customers. Customer 699 had an endbalance of 0,30 so the minimum endbalance of all customers should be at least 0,30:

That way we can get the Client ID context to the visual and not get the aggregates on the deltas from all the clientes and get the individual results for each client.

That happens because the measure that uses the swith, use the last day as its counter, and for that to work I use your Endbalance Cashback with help for check the last date that has a value greater than 0.

Since your Endbalance Cashback with help has a condition that anything goes below 0 put a 0 on it, and without the Customer Context it returns a cummulative of all the customers, so that cummulative will be always below 0 and your Endbalance will be 0 and that’s why when you take out the customer context, all the Endbalance with switch go back to 0, since the greatest value it will get is 0.