Waterfall value (get value from previous row to populate the next one) with arrayformula

40 views Asked by At

I am traying to resolve this but I think my brain is frozen and I cant find a solution online because I dont know how to correctly describe what I want to be able to find the answer.

So, for example I have this in google sheets,

Level Category 2
1 Car
2 Hatchback
2 Coupe
2 Convertible
1 Moto
2 Cruiser
2 Scooter

And I want this with the last column automatically expended using arrayformula:

Level Category 2 Category 1
1 Car Car
2 Hatchback Car
2 Coupe Car
2 Convertible Car
1 Moto Moto
2 Cruiser Moto
2 Scooter Moto

I want that in column C it will give me the corresponding text to number "1" and then for the rest of the rows it will give me the previous row until it find the next "1"

I was trying with filter, row, ifs but it is not working and my brain is melting, I was able to do that but not using arrayformula, tried to transform to arrayformula but it did not work. I want it to populate automatically. Can I have some help please? (Also I dont like to use query so something that dont use that pls)

1

There are 1 answers

5
rockinfreakshow On

You may try:

=scan(,A2:index(A:A,match(,0/(A:A<>""))),lambda(a,c,if(c=1,offset(c,,1),a)))

enter image description here

How Scan() works


Alternate using vlookup()

=arrayformula(let(Δ,match(,0/(A:A<>"")), Σ,A2:index(A:A,Δ), Λ,if(row(Σ)*Σ=row(Σ),row(Σ),),
 vlookup(row(Σ),{Λ,B2:index(B:B,Δ)},2,1)))

enter image description here