Forum Discussion

sookoon's avatar
sookoon
Copper Contributor
Jul 19, 2023
Solved

XLOOKUP return range reference instead of value in range

Hi everyone. 

 

Summary

I would like to see if I can use XLOOKUP and intersection to do a cross reference / horizontal vertical lookup. 

 

Detail

Let say my data (below) is in across rows and columns. Rows represent different months. Columns represent different products. 

 

Goal: Get Mar + Grape, which is 9 

 

Steps: To use intersection, I need to get range D1: D6 and range A5:G5. 

 

I try to use XLOOKUP: I find the value grape in the range A1:A6 and return array of the whole data table. The result from XLOOKUP seems to be a range A5:G5, and showed up as the values from this range ie grape 28 5 9 33 1 9 

 

Problem: In order to use intersection, I need the range reference A5:G5 rather than the values from A5:G5. 

 

Is there a way for XLOOKUP to return the range reference or a formula to get the range reference so that I use it in intersection ?

 

 

=XLOOKUP("grape", A1:A6, A1:G6)

 

 

 ABCDEFG
1 JanFebMarAprMayJun
2apple101216201816
3banana21264751935
4carrot4828304524
5grape28593319
6kiwi39252811413

 

  • sookoon 

    XLOOKUP does return an array - the first two formulas that I posted make use of that.

     

    I don't think there is an essentially simpler way to do a two-way lookup.

3 Replies

  • sookoon 

    Let's say you enter grape in A8 and Mar in B8.

    An XLOOKUP formula:

     

    =XLOOKUP(A8,A2:A6,XLOOKUP(B8,B1:G1,B2:G6))

     

    or reversing the lookups:

     

    =XLOOKUP(B8,B1:G1,XLOOKUP(A8,A2:A6,B2:G6))

     

    And an INDEX/XMATCH formula:

     

    =INDEX(B2:G6,XMATCH(A8,A2:A6),XMATCH(B8,B1:G1))

    • sookoon's avatar
      sookoon
      Copper Contributor

      Hi HansVogelaar thanks for your reply. 

       

      I have already tried XLOOKUP and INDEX MATCH. They can be used, but they make my formulas long and difficult to troubleshoot. 

       

      There is more to my situation: My table data has different versions, like below. The column month and row product may change across the different versions. 

       

      So far, I think the easiest way is to OFFSET(XLOOKUP( version , B:B, B:B )) to get the 2D array table out first. If version=ver1, table is B1:H6 If version=ver2, table is B8:H13. Then I need an inner XLOOKUP to get Mar + grape

       

      I do have a solution with INDEX and nested XLOOKUP and XMATCH. I am exploring if I can simplify my formula, by getting XLOOKUP to return a range. 

       

       ABCDEFGH
      1ver1 JanFebMarAprMayJun
      2 apple101216201816
      3 banana21264751935
      4 carrot4828304524
      5 grape28593319
      6 kiwi39252811413
      7        
      8ver2 MayJunJulAugSepOct
      9 mango826286
      10 banana1671593
      11 carrot28810439
      12 grape1015842111
      13 kiwi1934794

       

       

      • sookoon 

        XLOOKUP does return an array - the first two formulas that I posted make use of that.

         

        I don't think there is an essentially simpler way to do a two-way lookup.

Resources