Forum Discussion
MansoorAli
Dec 13, 2023Copper Contributor
Lookup with multiple criteria between 2 sheets
I have two sheets Sales <tblSales> Inventory<tblInventory> In sheet inventory I have14 columns data. But I am interested in column Code. It is auto generated. Like WT-B-1 for same...
NikolinoDE
Dec 14, 2023Gold Contributor
To achieve this, you can maybe use a combination of Excel functions like INDEX, MATCH, and IFAssuming your Sales table starts from cell A1 in the Sales sheet, and your Inventory table starts from cell A1 in the Inventory sheet, you can maybe use the following formula for cell C3 in the Sales sheet:
=IFERROR(INDEX(tblInventory[Code], MATCH(1, (tblInventory[Product]=B2)*(tblInventory[Name]=B3)*(tblInventory[Quantity]>0), 0)), "")
Upper formula is untested
Make sure to replace tblInventory with the actual table name in your Inventory sheet.
Here's how the formula works:
- INDEX(tblInventory[Code], ...) - This function returns the value in the Code column of the tblInventory table.
- MATCH(1, ...) - This function finds the position of the first "1" in the specified array.
- (tblInventory[Product]=B2)*(tblInventory[Name]=B3)*(tblInventory[Quantity]>0) - This is an array formula that checks for multiple criteria:
- Checks if the Product column in Inventory matches the value in B2 (Water Tank in this case).
- Checks if the Name column in Inventory matches the value in B3 (Bash in this case).
- Checks if the Quantity in Inventory is greater than 0.
- IFERROR(..., "") - This function handles errors. If no match is found, it returns an empty string (""), indicating that there is no stock available.
Now, when you copy this formula down in column C of the Sales sheet, it will automatically pick the correct Code for each sale, considering the specified criteria and quantity.
Remember to adjust the table name and column references based on your actual data layout. Additionally, if you are entering this formula into an Excel table, you might need to use structured references. The text, steps and formula was created with the help of AI. If the Steps/formula don’t works please provide more information.
Hope this will help you.
Was the answer useful? Mark as best response and like it!
This will help all forum participants.
MansoorAli
Dec 15, 2023Copper Contributor
Thanks for Replying,
I am attaching photos see them sir,
I changed some of references as you mentioned.
But you can see C-PO-1 is not changed when stock for C-PO-1 ends in Inventory.
It should become C-PO-2 after I sale 200 units.
Rest is in your hands