Three Dimensional Lookup Using INDEX/MATCH

前端 未结 11 1228
闹比i
闹比i 2020-12-01 14:28

This was taken and improved slightly from Question that has since been deleted

For those who can see deleted posts, it was taken from here: https://

相关标签:
11条回答
  • 2020-12-01 14:48

    This solution works in all conditions discussed so far (let me know of any condition that it does not work and I’ll try to cover it). I’m posting this as a separated answer as the formulas applied in prior answer rightly apply to the conditions stated in them, as such they will be useful to users with those specific scenarios, so they don’t need to apply these long formulas.

    This formula assumes the data is located at B6:E30 (in order to ensure it can be applied regardless of the source range location).

    This formula uses the Index\Match functions and it’s a Formula Array.

    FormulaArrays are entered pressing [Ctrl] + [Shift] + [Enter] simultaneously, you shall see { and } around the formula if entered correctly

    Syntax:

    =IFERROR(INDEX(DataRng,
    MATCH(Value1,NamesRng,0)
    +IFERROR(MATCH(Value2,INDEX(NamesRng,
    1+MATCH(Value1,NamesRng,0))
    :INDEX(NamesRng, IFERROR(MATCH(Value1,NamesRng,0)
    +MATCH("#",IF((INDEX(Col1Rng,1+MATCH(Value1,NamesRng,0))
    :INDEX(Col1Rng,ROWS(NamesRng)))="","#","!"),0),
    ROWS(NamesRng))),0),NA()),MATCH(ValCol,DataHdr,0)),"")
    

    Arguments: Assuming the data is located at B6:E30.

    Value1= Name to be found in Data, i.e. George, Scott, etc.

    Value2= Detail to be found in Data, i.e. Detail1, Detalle2, etc.

    ValCol = Column to be found in Data i.e. Column1, Column2, etc.

    DataRng= $B$6:$E$30

    DataHdr= $B$6:$E$6

    NamesRng= $B$6:$B$30

    Col1Rng= $C$6:$C$30

    1st MATCH: Retrieves the position of the Name:

    MATCH(Value1,NamesRng,0)
    

    2nd MATCH: Retrieves the end position of the Name’s corresponding Details, which is determined by a blank value in column C or the end of the data range:

    MATCH("#",IF((INDEX(Col1Rng, 1 + 1stMATCH)
    :INDEX(Col1Rng,ROWS(NamesRng)))="","#","!"),0),
    

    Builds a Range (vRange): With the Names's Details using the 1st and 2nd match functions. If 2nd Match returns an error then it uses the last row of the Data range:

    INDEX(NamesRng, 1 + 1stMATCH )
    :INDEX(NamesRng, IFERROR( 1stMATCH + 2ndMATCH, ROWS(NamesRng)))
    

    3rd MATCH: Retrieves the position of the Detail within the vRange. It returns #NA if the combination is not present.

    IFERROR(MATCH(Value2, vRange,0), NA())
    

    Adding the results of the 1st and 3rd match functions obtains the Row index of the Name`Detailcombination or#NAif no found. The Column index is obtained with a Match from the Header of the Data. It then applying the INDEX function to the Data Range returns the value of theName\Detail\Columncombination. If theName\Detail` combination is not found it returns blank.

    =IFERROR( INDEX( DataRng, 1stMATCH + 3rdMATCH, MATCH(Column,DataHdr,0)),"")
    

    With the results located at H6:L37 enter this Formula Array in J8 then copy to K8:L37 and to J9:L37:

    =IFERROR( INDEX($B$6:$E$30,
    MATCH($H8,$B$6:$B$30,0)
    +IFERROR( MATCH($I8, INDEX($B$6:$B$30,
    1+MATCH($H8,$B$6:$B$30,0))
    :INDEX($B$6:$B$30, IFERROR(MATCH($H8,$B$6:$B$30,0)
    +MATCH("#", IF((INDEX($C$6:$C$30,1+MATCH($H8,$B$6:$B$30,0))
    :INDEX($C$6:$C$30,ROWS($B$6:$B$30)))="","#","!"),0),
    ROWS($B$6:$B$30))),0),NA()),
    MATCH(J$6,$B$6:$E$6,0)), "")
    

    0 讨论(0)
  • 2020-12-01 14:50

    Wow... So many solutions already.

    I think a simpler solution could be using offset to get a more generic answer.

    =INDEX($A$1:$D$9, MATCH($G$3,OFFSET($A$1,MATCH($G$2,$A$1:$A$9,0),0,3,1),0)+MATCH($G$2,$A$1:$A$9,0), MATCH($G$4,$B$1:$D$1,0)+1)
    

    The only variable to look for is 3 which is the number of M/N/P options present because that will affect the number of rows. Otherwise, the solution works fine in all possible scenarios and different orders.

    0 讨论(0)
  • 2020-12-01 14:52

    I would use the area (4th parameter) of Index(). Below is a screenshot of test data. This example assumes the same columns and keys are sorted and consistent.

    This works by using (Range1,Range2) as the first parameter of index. For the 4th parameter of index, use N for which area in the () you want Index to return.

    0 讨论(0)
  • 2020-12-01 14:56

    When I have more than two inpunts for a data search I prefer to have the data organized as shown in the figure, so that I can use a pivot table and get it to organize the data in rows and columns as I like.

    Then I use GETPIVOTDATA to search for a value.

    Cell G9 contains this formula:

    =GETPIVOTDATA("Value";$F$3;"Name";G15;"Letter";G16;"Column";G17)

    0 讨论(0)
  • 2020-12-01 14:59

    I used an IF() statement array formula to find what the P row number was after the George row... I also needed to use the MIN() function to get the first P row number after the name.

    Beyond that, it's a simple INDEX() function.... that racked my brain for over an hour :).

    =INDEX($A$1:$D$9,MIN(IF((ROW(A1:A9)>MATCH($F$4,A1:A9,0))*(A1:A9=$F$5),ROW(A1:A9),"")),MATCH($F$6,$A$1:$D$1,0))

    Don't Forget!
    Use Ctrl+Shift+Enter when finishing the formula, so it gets evaluated as an array formula.

    0 讨论(0)
提交回复
热议问题