xlookup against multiple columns in lookup array

RookieExcel22

New Member
Joined
Aug 11, 2023
Messages
12
Office Version
  1. 365
Platform
  1. Windows
Hi,

I have the below table of data

Column GCol HCol ICol J
ValueValueQuestion 1Question 2
ABAD32
AC45

I want to bring the data in column Question 1 into a table that looks like this

Col ACol B
ValueQuestion 1
AB3
AC4
AD3


I know I can use an ifna(vlookup but that is a lot of effort. I tried an xlookup hoping it could look against both value columns but that did not work. I ended up using this formula:

=IFNA(XLOOKUP(A2,$G$2:$G$3,XLOOKUP(B$1,$I$1:$J$1,$I$2:$J$3)),XLOOKUP(A2,$H$2:$H$3,XLOOKUP(B$1,$I$1:$J$1,$I$2:$J$3)))

While it did work, it is a bit of effort to set up as I have 15 value columns. Wondering if there is a simpler way! Thank you.
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
power query
Book1
ABCDEFG
1Column GCol HCol IColumnJValue.1Question 1Question 2
2ValueValueQuestion 1Question 2AB32
3ABAD32AC45
4AC45AD32
Sheet1


Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column G", type text}, {"Col H", type text}, {"Col I", type any}}),
    #"Promoted Headers" = Table.PromoteHeaders(#"Changed Type", [PromoteAllScalars=true]),
    #"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{"Value", type text}, {"Value_1", type text}, {"Question 1", Int64.Type}, {"Question 2", Int64.Type}}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type1", {"Question 1", "Question 2"}, "Attribute", "Value.1"),
    #"Reordered Columns" = Table.ReorderColumns(#"Unpivoted Columns",{"Attribute", "Value.1", "Question 1", "Question 2"}),
    #"Removed Columns" = Table.RemoveColumns(#"Reordered Columns",{"Attribute"}),
    #"Sorted Rows" = Table.Sort(#"Removed Columns",{{"Value.1", Order.Ascending}})
in
    #"Sorted Rows"
 
Upvote 0
power query
Book1
ABCDEFG
1Column GCol HCol IColumnJValue.1Question 1Question 2
2ValueValueQuestion 1Question 2AB32
3ABAD32AC45
4AC45AD32
Sheet1


Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column G", type text}, {"Col H", type text}, {"Col I", type any}}),
    #"Promoted Headers" = Table.PromoteHeaders(#"Changed Type", [PromoteAllScalars=true]),
    #"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{"Value", type text}, {"Value_1", type text}, {"Question 1", Int64.Type}, {"Question 2", Int64.Type}}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type1", {"Question 1", "Question 2"}, "Attribute", "Value.1"),
    #"Reordered Columns" = Table.ReorderColumns(#"Unpivoted Columns",{"Attribute", "Value.1", "Question 1", "Question 2"}),
    #"Removed Columns" = Table.RemoveColumns(#"Reordered Columns",{"Attribute"}),
    #"Sorted Rows" = Table.Sort(#"Removed Columns",{{"Value.1", Order.Ascending}})
in
    #"Sorted Rows"

Ah not familiar with power query. I will have to do some research! Thank you.
 
Upvote 0
A formula option
Fluff.xlsm
GHIJKLM
1ValueValueQuestion 1Question 2Question 1
2ABAD32AB3
3AC45AD3
4AC4
5AF 
Master
Cell Formulas
RangeFormula
M2:M5M2=XLOOKUP(L2,TOCOL($G$2:$H$3,1,1),TOCOL(IF($G$2:$H$3<>"",CHOOSECOLS($I$2:$J$3,XMATCH(M$1,$I$1:$J$1)),1/0),2,1),"")
 
Upvote 0
Solution
A formula option
Fluff.xlsm
GHIJKLM
1ValueValueQuestion 1Question 2Question 1
2ABAD32AB3
3AC45AD3
4AC4
5AF 
Master
Cell Formulas
RangeFormula
M2:M5M2=XLOOKUP(L2,TOCOL($G$2:$H$3,1,1),TOCOL(IF($G$2:$H$3<>"",CHOOSECOLS($I$2:$J$3,XMATCH(M$1,$I$1:$J$1)),1/0),2,1),"")
Awesome this worked. Thank you so much!
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0
A formula option
Fluff.xlsm
GHIJKLM
1ValueValueQuestion 1Question 2Question 1
2ABAD32AB3
3AC45AD3
4AC4
5AF 
Master
Cell Formulas
RangeFormula
M2:M5M2=XLOOKUP(L2,TOCOL($G$2:$H$3,1,1),TOCOL(IF($G$2:$H$3<>"",CHOOSECOLS($I$2:$J$3,XMATCH(M$1,$I$1:$J$1)),1/0),2,1),"")

Hi, does this have a max character return count? I get a #calc error on some of my columns. I noticed if I remove characters to a max of 255 the #calc disappears. Anything over 255 and it comes back? Thanks!
 
Upvote 0
It works for me with more than 255 characters. Can you post the actual data.
 
Upvote 0

Forum statistics

Threads
1,216,030
Messages
6,128,411
Members
449,449
Latest member
Quiet_Nectarine_

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