I have a google sheet where
I have tried brute force. I have tried XLOOKUP. I simply can't figure out how to make col D come out accurate during and after the TEXT skips.
D2=XLOOKUP(1000, $C$2:indirect("C"&row()), $B$2:indirect("B"&row()), "calculate normally", -1, -1)
I think XLOOKUP will likely end up being the answer, but I've spent all evening on it and all I got was a bloody forehead. Obviously, in a perfect world, I'll be able to wrap this in an ARRAYFORMULA
and have it populate down
For column B you can use:
=SCAN(1,SEQUENCE(ROWS(A3:A)),LAMBDA(v,a,IF(INDEX(A3:A,a)=INDEX(A2:A,a),v+1,1)))
And for column D:
=SCAN(0,SEQUENCE(ROWS(A3:A)),LAMBDA(v,a,
IF(INDEX(A3:A,a)=FALSE,INDEX(B3:B,a),
IF(INDEX(A2:A,a)=FALSE,1,
IF(ISTEXT(INDEX(C3:C,a)),v,v+1)))))
You asked me to get you through the formulas:
=SCAN(0,A1:A10,LAMBDA(a,v,a+v))
you'll have a cumulative sum, if you use =SCAN(1,A1:A10,LAMBDA(a,v,a*v))
:For more information read: SCAN - in your particular case, since you had to compare values from different cells of different rows or different columns, I decided to use it in a not very conventional way: instead of giving a group of cells or values, I gave it a sequence of numbers that represents the amount of rows in between A3 and last row in A: SEQUENCE(ROWS(A3:A))
and combined with INDEX it let me in the formula of B and in the formula of D to go through each of the rows of the needed columns to fetch the conditions set by you. Yes, probably with OFFSET you could have solved it too, but to use a similar approach in both formulas I inclined for this. For example in B column: INDEX(A3:A,a)=INDEX(A2:A,a)
compares the values from a cell an the one that is one cell up (observe that in second member of equation it starts from A2 instead of A3. And in Column D I can return the value from column B if A is false with INDEX(B3:B,a)
and check if C is text with ISTEXT(INDEX(C3:C,a))
- all with that value of the sequence considered each time.
I think that is probably already clear but in B formula I stated that if the cell in A is equal to the one above it sums one to the previous "saved" value (called "v" in my lambda function) or else it "starts" again from 1. In D column you also have those conditionals set, I think they're clearer because of the organizations in different lines. (Hope it's useful despite my English!)