I have the following list in a Google Sheet:
| List |
|---|
| Apple |
| Banana |
| Pear |
| Grapes |
| Kiwi |
| Mandarin |
| Papaya |
| Orange |
| Tomato |
| Plum |
| Watermelon |
Based on these two following conditions, I'm trying to get the preceding number of n results based on the position of the identifier in the list.
| Identifier | Number of Preceding Results Required |
|---|---|
| Orange | 5 |
Ideally, the results will be displayed as an array, that way, the single formula can dynamically change the results based on the 2 conditions.
| Expected Results |
|---|
| Pear |
| Grapes |
| Kiwi |
| Mandarin |
| Papaya |
Attempts:
I've tried the following 3 formulas but unfortunately 2 return only 1 value, and I keep getting an error in the third attempt.
1.=ARRAY_CONSTRAIN(FILTER({A3:A,ROW(A3:A)},A3:A=C3),D3,1)
2.=QUERY(A:A,"SELECT Col1 WHERE Col1 = '"&C3&"' LIMIT "&D3&"")
3.=ARRAYFORMULA(QUERY(QUERY(TO_TEXT(A3:A),"select Col1 where Col1='"&$C$3&"'",0),"Select * Offset " &COUNTIF(A3:A,$C$3)-$D$3))
Testing Google Sheet link with public access: here
Image of current worksheet:
