Can you use AND / OR in an INDEX MATCH

Copper Contributor

Hi I have am array formula that looks like this:

 

=INDEX('Rebate report'!A:A,MATCH(1,('Rebate report'!A:A=A2)*('Rebate report'!B:B=B2)*('Rebate report'!C:C=C2),0),1) which works.

 

I want to add in an OR function for the name in column A. I will add this name in Column T. In other words the match is correct if column A or T match A2 and COL B=B2 and COL C=C2 also match the criteria

 

I tried using the + to add T criteria but gave me a 0

=INDEX('Rebate report'!A:A,MATCH(1,('Rebate report'!A:A=A2)*('Rebate report'!B:B=B2)*('Rebate report'!C:C=C2)+('Rebate report'!A:A=T2),0),1)

 

Thanks for the help!

59 Replies

@Hans Vogelaar @Sergei Baklan

I hope one of you can help me. I have three sheets; an income sheet, expense sheet, and ledger schedule. Both income and expense sheet contain lines of transactions with entry numbers (INCxxx for income, and EXPxxx for expenses), amounts, and account numbers.

The ledger schedule lists all transactions from both income and expense sheet upon selection of a specific account from a drop-down list. 

I have created an index/match formula to retrieve the information from the expense sheet, but I'd like to include the income sheet in the same formula.

My formula so far is : 
=IFNA(INDEX(Expenses!$B:$B,MATCH(1,(Expenses!$B:$B>'Ledger Schedule'!$B9)*(Expenses!I:I='Ledger Schedule'!$B$4),0)),"")

Column B refers to the transaction number (which is unique for each transaction), column I the account number that is selected from the drop-down list.

Can I use the OR function to let the match formula look at either income or expense sheet and retrieve the relevant transaction? Thank you in advance!

@joostbr1965 

Does column B of the Ledger Schedule sheet contain the entry numbers? If so, try

 

=IFNA(IF(LEFT('Ledger Schedule'!$B$4,3)="EXP", INDEX(Expenses!$B:$B,MATCH(1,(Expenses!$B:$B>'Ledger Schedule'!$B9)*(Expenses!I:I='Ledger Schedule'!$B$4),0)), INDEX(Income!$B:$B,MATCH(1,(Income!$B:$B>'Ledger Schedule'!$B9)*(Income!I:I='Ledger Schedule'!$B$4),0))), "")

 

Change Income to the real name of the expense sheet if necessary.

@Hans Vogelaar 

Hi Hans, thank you for the response. Really appreciate your efforts in providing the suggested solution. Column B in the expense & income sheets indeed contains the entry numbers.

 

Unfortunately, it does not work. I realize that my explanation might not have been totally complete. Cell B4 is referring to the value in the drop-down list from where I can select the account number.

I've tried to tweak the formula a bit to make it point to the correct cell reference, but it still does not work. 

 

Hopefully, the below screenshots provide more insights.

In cell B9 it should always get the first possible record from the expense or income sheet that contains the selected account number.

 

Cell B10 will then pull the next record, B11 the record after that, etc. until the final record has been listed.

 

If both income and expense sheet records can be pulled chronologically, that would be awesome, but I realize that might be quite a challenge, so it's okay to list the expense records first, and after that the income records for that relevant account.

 

Formula Cell B9.PNGFormula Cell B10.PNG

 

Hope this helps and thank you again! :)

@joostbr1965 

Which version of Excel do you have?

@Hans Vogelaar 

 

Microsoft Excel 365

@joostbr1965 

That's good, because it has functions suitable for that such as VSTACK. But unfortunately, I don't have 365, so I'm tagging a few of my friends:

@Sergei Baklan @mathetes @mtarler @Peter Bartholomew 

@joostbr1965 

I am not sure why we are working at the back end of a 5 year old discussion.  Wouldn't a fresh discussion with less legacy discussion be better?

@Hans Vogelaar 

Did you put together any test workbooks?  Having something to work on would help.

My immediate thoughts lean towards FILTER/VSTACK/SORT but it would be nice to see an example.

 

@Peter Bartholomew 

No, I don't have a test workbook, sorry.

First, i agree with Peter that this should have been a new thread.
Second, I would strongly recommend you consider re-doing you workbook to have ALL entries in ONE table and then have other tabs as reports (expense report just filters all the expense lines, Income report filters all the income lines, account reports ...)
Third, I recommend you make use of the the 'Format as a Table' function on the Home menu. This will let you refer to data based on a Table reference instead of columns so instead of Income!$B:$B it might be Income[Voucher Number]. This makes it easier to work with, easier to read (once you get used to it) and then excel only looks at the data rows instead of the entire column of the worksheet (over a million rows). For the below I will pretend you format the Income table as a table called INCOME and the Expense table as a table called EXPENSE.
So a solution to the existing, with Excel 365 you should be able to use:
=SORT(VSTACK(FILTER(INCOME, INCOME[Account Number]=$B$4, ""),FILTER(EXPENSE, EXPENSE[Account Number]=$B$4)))
My apologies for replying to an old thread.

The tables have been formatted as and the formula has been really helpful, it's working now with a bit of tweaking and testing. Really appreciate all the help! Have a great day!

@Sergei Baklan 

 

Hi Sergei, What does the INDEX function inside the MATCH function signify and How can we use INDEX inside MATCH or INDEX function?

@kalyansp 

That's the trick for the Excel which doesn't support dynamic arrays, e.g. Excel 2016. If in such Excel we use formula like

=INDEX(A:A, MATCH( 1, (B:B=2)*(C:C=3), 0 ) )

here (B:B=2)*(C:C=3) is an array and we shall use above formula as an array one, i.e. to enter with Ctrl+Shift+Enter.

However, with INDEX( (B:B=2)*(C:C=3), 0 ) which returns exactly the same array we may use formula

=INDEX(A:A, MATCH( 1, INDEX( (B:B=2)*(C:C=3), 0 ), 0 ) )

as regular one, i.e. enter it simply with Enter.

Above is not required for the Excel which supports dynamic arrays (Excel 365).

And on practice please don't use entire columns as in above sample, that significantly affects the performance. Structured tables, dynamic ranges or fixed ranges instead.

hello @Sergei Baklan 

I need help to add one more condition in Index and Match function.

B2 cell formula is working well

sheet1: b3=INDEX(Sheet2!$O$2:$AJ$2488,MATCH(Sheet1!D3,Sheet2!$J$2:$J$2488,0),MATCH(Sheet1!A3,Sheet2!$O$1:$AJ$1,0))

But I need to add one more condition-date range-Workdate need to within (sheet2) Start_date and end_date

I did try to put formula as array B2==INDEX(Sheet2!$O$2:$AJ$8,MATCH(1,INDEX((Sheet1!D2=Sheet2!$J$2:$J$8)*((C2>=Sheet2!$K$2:$K$6)*(Sheet1!C2<=Sheet2!$L$2:$L$6))*(Sheet1!A2=Sheet2!$O$1:$AJ$1),0),))

But didn't work. 

Below is worksheet link

 

https://docs.google.com/spreadsheets/d/1KLxXNEjwuLOMMJqwAhDtt_M2f9YjlV6N/edit?usp=sharing&ouid=11183... 

Thanks Lot

@NPfor 

That could be

=INDEX(
    'Maximo Rate table'!$O$2:$AJ$2488,
    MATCH( 1,
        INDEX(
            (D2 = 'Maximo Rate table'!$J$2:$J$2488) *
            (C2 >= 'Maximo Rate table'!$K$2:$K$2488) *
            (C2 <= 'Maximo Rate table'!$L$2:$L$2488),
            0 ),
    0 ),
    MATCH(A2, 'Maximo Rate table'!$O$1:$AJ$1, 0)
)

First MATCH is for rows with all conditions, second MATCH is for columns.

Formula is in column I (I2, etc) in attached.

Thanks lot @Sergei Baklan 

@NPfor , you are welcome

=INDEX('NM & CRM'!$B$4:$D;MATCH(B20;'NM & CRM'!$D$4:$D;0);2)&INDEX('NM & CRM'!$G$4:$I;MATCH(B20;'NM & CRM'!$I$4:$I;0);2)

Sir, can you help me improve this formula, because when I run the formula, 2 names appear. I only want 1 name.

@ricardo2260 I want to retrieve data in these 2 tables with options, search in table A, if there is, retrieve column data, if there is none, search in table B, if found in column B, retrieve the column.

so I see you are actually using google sheets and not excel so i don't even have to ask what version, which is good because you should use some newer functions. if I'm reading your formula right try:
=LET(first, XLOOKUP(B20, 'NM & CRM'!$D$4:$D, 'NM & CRM'!$C$4:$C,""), IF(first<>"",first, XLOOKUP(B20, 'NM & CRM'!$I$4:$I, 'NM & CRM'!$H$4:$H,""))
basically do the first lookup and assign it to 'first' then check if a value was found and if not do the second lookup.
I can do it, thanks for the help mtarler