Trying to always compute top down in a single sortable table
I have a table that needs to always be computed from the top row down, even as rows are resorted. This is because some calculations get reset when a condition is met (in the example below, when the number of Apple shares owned reaches 0, the cost basis is reset).
I got it to work using two tables but this is really inconvenient and I'm sure there's a way to do it in a single table. Basically I created a second table with a "chrono" column that numbers each row, then I got B2 to always return whatever is in B2 of the first table, C2 to mirror C2 etc. This way I can sort the first table, and the second one just re-fills without having its rows resorted (which broke my calculations if I everything was in one single table)
Is there a way to do all this using the table's row numbers instead of my "Chrono" column ?
Two columns make use of the chrono column
Column H:
IF(B2≠"",SUMIFS(M,Chrono,"<"&ROW()−1,Market,C2)+M2,"")
Column I :
IF(B2≠"",IFERROR(IF(B2="BUY",VLOOKUP(MAXIFS(Chrono,Chrono,"<"&A2,Market,C2),Chrono:'Total Cost
Holdings',9,FALSE)+(D2×E2),VLOOKUP(MAXIFS(Chrono,Chrono,"<"&A2,Market,C2),Chrono:J,10,FALSE)×H2),E2×D2),"")
iMac 27″, macOS 13.6