Question
XLOOKUP with flexible column for return_array and not unique values in lookup_array
0 | A | B | C | D | E | F | G | H | I | J | K | L | M |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | Products | Shop | 2023-S | 2023-M | 2024-S | 2024-M | |||||||
2 | |||||||||||||
3 | Product A | Shop3 | 80 | 2% | 120 | 22% | |||||||
4 | Product B | Shop1 | 320 | 17% | 400 | 15% | Data from Column | ||||||
5 | Product B | Shop3 | 470 | 30% | 750 | 8% | 2024-S Selected | 2024-M | |||||
6 | Product B | Shop2 | 500 | 4% | 70 | 4% | 400 | 15% | |||||
7 | Product C | Shop2 | 160 | 10% | 245 | 10% | 400 | 35% | |||||
8 | Product D | Shop1 | 500 | 8% | 130 | 4% | 70 | 4% | |||||
9 | Product D | Shop4 | 130 | 11% | 130 | 4% | 520 | 42% | |||||
10 | Product E | Shop2 | 75 | 8% | 650 | 15% | 130 | 4% | |||||
11 | Product E | Shop1 | 60 | 47% | 90 | 7% | 90 | 7% | |||||
12 | Product E | Shop4 | 500 | 25% | 400 | 35% | 130 | 4% | |||||
13 | Product E | Shop3 | 350 | 9% | 140 | 13% | 130 | 9% | |||||
14 | Product F | Shop2 | 60 | 30% | 130 | 9% | 70 | 16% | |||||
15 | Product G | Shop2 | 90 | 5% | 370 | 12% | |||||||
16 | Product H | Shop1 | 390 | 27% | 70 | 16% | |||||||
17 | Product H | Shop2 | 70 | 18% | 520 | 42% |
In Range M6:M14
I want to get the corresponding data based on the values in Range K6:14
.
However, I want to have the flexibility that the values in Range M6:M14
are selected based on the column header entered in Cell M5
.
In the table Column 2024-M
is selected.
If I change Cell M5
for example to Column Header Products
the Range M6:M14
should look like this:
Product B
Product E
Product B
Product H
Product D
Product E
Product D
Product F
Product H
Summarized, I am looking for something like this:
Range M6:14 =XLOOKUP(K6:K14,$H$1:$H$17,Based on input in Cell $M$5,NA(),0)
Note:
- The
lookup_array
will always be the same. In this exampleRange $H$1:$H$17
. - Values in the
lookup_array
are not unique. In this example130
,400
and70
. - If a value in the
lookup_array
is not unique it will always appear with the exact same frequency inRange M6:M14
as you can see for130
,400
and70
in the example. - The solution from this question does not work here because the results in
Range M6:M14
should not only be corresponding to the valuesColumn A
. It can be any column in the table beased on the Column Header entered inCell M5
.
What formula do I need to make the outcome in Range M6:M14
work based on the selected Column Header in Cell M5
?