I have a dataframe of financial data. I am trying to make a more accurate representation of current balance from it. The issue is the data has a "balance" that is only good at the month end. I need to adjust the balance on a daily basis off of that days transactions.
In order to get the start balance, I created a variable that is the lagged value of ending balance. Then I made a variable, calculated balance to get the "correct" balance But since the start balance was already made, it keeps going back to square 1. Example shown below:
| Date       Name    Start Balance  Adjustment  End Balance   Calculated Balance |  |
+--------------------------------------------------------------------------------+--+
| 6/30/2020  X       80             20          100           100                |  |
| 7/1/2020   X       100            10          100           110                |  |
| 7/2/2020   X       100            10          100           110                |  |
+--------------------------------------------------------------------------------+--+
data <- tibble(
  Date = c("2020-06-29", "2020-06-30", "2020-07-01", "2020-07-02"),
  Name = c("X", "X", "X", "X"),
  Start_Balance = c(80, 80, 100, 100),
  Adjustment = c(0, 20, 10, 10),
  End_Balance = c(80, 100, 100, 100),
  Calc_Balance = c(80, 100, 110, 110),
  What_I_Need = c(80, 100, 110, 120)
)
What would be the correct way to get this to work
