How to complete XLOOKUP across a row but have the lookup array change dynamically by column in another table

armsafna

New Member
Joined
Mar 12, 2023
Messages
9
Office Version
  1. 365
Platform
  1. Windows
For example: let's say I have a six-sided die with sides A through F.

I roll the die four times and record results per trial as follows:
TrialRoll 1Roll 2Roll 3Roll 4
1ABCD
2EFAB
3EDCF

Now I have another table where I want to output the roll during which each letter was the outcome per trial:

Outcome Trial 1Trial 2Trial 3
A=XLOOKUP($A6,$B2:$E2,$B$1:$E$1) = Roll 1=XLOOKUP($A6,$B2:$E2,$B$1:$E$1) = Roll 1
(I want) =XLOOKUP($A6,$B3:$E3,$B$1:$E$1) = Roll 3
B=XLOOKUP($A7,$B2:$E2,$B$1:$E$1) = Roll 2
C=XLOOKUP($A8,$B2:$E2,$B$1:$E$1) = Roll 3
D=XLOOKUP($A9,$B2:$E2,$B$1:$E$1) = Roll 4
E=XLOOKUP($A10,$B2:$E2,$B$1:$E$1) = N/A
F=XLOOKUP($A11,$B2:$E2,$B$1:$E$1) = N/A

It works great for the column 'Trial 1', updating the lookup value. When I try to drag it across the column, I want it to change the lookup table from B2:E2 to B3:E3 corresponding to the Trial 2 results which are displayed along a row rather than a column in the other table. See the 'Trial 2' column for an example of the error in bold. What I want it to do is recognize I am referring to Trial 2, and search for A6 (the letter "A") in the 'Trial 2' row of table 1, and therefore dynamically adjust the lookup table to B3:E3. Is there a way to do this without transposing Table 2 to match Table 1? (i.e. with trials in columns instead of rows?)
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Maybe:

Book1
ABCDE
1TrialRoll 1Roll 2Roll 3Roll 4
21ABCD
32EFAB
43EDCF
5
6OutcomeTrial 1Trial 2Trial 3
7ARoll 1Roll 3#N/A
8BRoll 2Roll 4#N/A
9CRoll 3#N/ARoll 3
10DRoll 4#N/ARoll 2
11E#N/ARoll 1Roll 1
12F#N/ARoll 2Roll 4
Sheet4
Cell Formulas
RangeFormula
B7:D12B7=INDEX($B1:$E1,MATCH($A7:$A12,FILTER($B2:$E4,$A2:$A4=RIGHT(B6)+0),0))
Dynamic array formulas.


Do you have to worry about getting the same result more than once in a given trial? 2 A's for example?
 
Upvote 1
Solution
Worked like a charm thank you! I imagine that as a general rule using INDEX and MATCH where the row is filtered to match a value in a column in another table works to solve this as a general issue?
 
Upvote 0
Well, every situation is different. I could have used OFFSET instead of FILTER, and it would have worked OK. But OFFSET is volatile (it recalculates every time anything on the sheet recalculates, potentially slowing the sheet down), so most people avoid it whenever possible. Using FILTER is definitely a tool to keep in your bag of tricks though, especially when the rows are easily identified as they are in this example.

Glad I could help! :cool:
 
Upvote 0

Forum statistics

Threads
1,215,775
Messages
6,126,826
Members
449,341
Latest member
addman24

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top