Find a value based on two criteria in other columns

Yamezz

Active Member
Joined
Nov 22, 2006
Messages
367
Office Version
  1. 2019
I have a table of data with headers in A2:AB2 and actual data in A3:AB15. Column A is a listing of Product Names and columns K:AB contain alternating stocktake numbers and the date that stocktake was done.
From this data, I need to return the latest stocktake date in a particular row that meets two criteria.
If cell A20 contains the Product Name of interest, I need to find the row where this Product Name appears AND "X" appears in C3:C10 ("X" is text)
There may be multiple instances of A20, but only one of these will also have "X" in column C.
From the row identified above, find the MAX value in that row (this will be a date)

I'd be grateful for any help.
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Does anyone have any suggestions for me?
A suggestion would likely come much quicker if you gave some small representative sample data with XL2BB and explained what result(s) you would want from that data and why.
 
Upvote 0
Hello Peter. Thanks for clicking on my question.

I have anonymised the data and included a mini sheet.
Sales and Production Planning.xlsx
ABCDEFGHIJKLMNOPQRSTUVWXYZAAAB
2ProductBatchCurrentBlahBlah2Blah3Blah4Blah5Blah6Blah7NumberDateNumber2Date3Number4Date5Number6Date7Number8Date9Number10Date11Number12Date13Number14Date15Number15Date17
3Apple14XBlahBlahBlahBlahBlahBlahBlah1,60806-Mar-1840030-Jun-2229431-Aug-2225726-Oct-229705-May-235424-Jun-23
4Apple16BlahBlahBlahBlahBlahBlahBlah1,62012-Mar-191,34530-Jun-221,30031-Aug-221,33826-Oct-221,10805-May-231,11101-Jul-23
5Apple17BlahBlahBlahBlahBlahBlahBlah1,90501-Mar-191,90530-Jun-221,90531-Aug-221,90526-Oct-221,88305-May-231,89029-Jun-23
6Banana22XBlahBlahBlahBlahBlahBlahBlah1,53615-Feb-231,25905-May-23104429-Jun-23
7Cherry18XBlahBlahBlahBlahBlahBlahBlah2,29217-Dec-211,70530-Jun-221,43831-Aug-221,33326-Oct-2229205-May-2394029-Jun-23
8Grape17XBlahBlahBlahBlahBlahBlahBlah8,97605-Nov-192,95230-Jun-222,65231-Aug-222,39526-Oct-221,87605-May-231,53624-Jun-23
9Grape19BlahBlahBlahBlahBlahBlahBlah2041-Jul-2320007-Jul-23
10Pear21XBlahBlahBlahBlahBlahBlahBlah2,50023-Apr-222,14930-Jun-221,76827-Aug-221,47226-Oct-2279805-May-2352329-Jun-23
11Pear22BlahBlahBlahBlahBlahBlahBlah1,3681-Jul-23
12Strawberry18XBlahBlahBlahBlahBlahBlahBlah1,54823-Dec-2081130-Jun-2224031-Aug-229026-Oct-2222705-May-236601-Jul-23
13Orange19XBlahBlahBlahBlahBlahBlahBlah1,68020-May-221,67230-Jun-221,67231-Aug-221,54926-Oct-221,65605-May-231,25524-Jun-23
14Blueberry20XBlahBlahBlahBlahBlahBlahBlah2,70617-Dec-211,73730-Jun-221,27131-Aug-221,23726-Oct-221,27505-May-2388529-Jun-23
15Blueberry21BlahBlahBlahBlahBlahBlahBlah1431-Jul-23
16
17
18
19ProductLast Stocktake
20Apple24-Jun-23
Stock (2)

The formula in B20 should return 24-Jun-23. This is determined by checking the table for the Product of interest (Apple), determining which batch is the current one (designated by an "X" in column C) and looking across that row to find the date of last stocktake.
 
Upvote 0
Thanks for the XL2BB sample data and explanation.
Try this (but check the name of your table)

Excel Formula:
=IFERROR(LOOKUP(9^9,INDEX(Table1,AGGREGATE(15,6,(ROW(Table1)-ROW(Table1[#Headers]))/((Table1[Product]=A19)*(Table1[Current]="X")),1),0)),"")
 
Upvote 0
Solution
Thanks for the XL2BB sample data and explanation.
Try this (but check the name of your table)

Excel Formula:
=IFERROR(LOOKUP(9^9,INDEX(Table1,AGGREGATE(15,6,(ROW(Table1)-ROW(Table1[#Headers]))/((Table1[Product]=A19)*(Table1[Current]="X")),1),0)),"")
Thank you Peter. I have spent the morning testing this and it seems to work in all instances.

If you have time, I'd love to understand why you took the approach you did. I was muddling about with INDEX, MATCH and MAX functions, trying to find the row number that met the conditions of Product and "X" and then find the MAX value in that row, which would be the most recent date.
 
Upvote 0
If you have time, I'd love to understand why you took the approach you did.
Why is a difficult question to answer. Experience I guess.
The INDEX/AGGREGATE structure picks out the row that matches the product and "X".
LOOKUP a very big number (9^9) in that row can't find the very big number so returns the last number that it can find in the row. That is the right hand date in the row.

I was muddling about with INDEX, MATCH and MAX functions,
I don't know much about your data but MAX may not get the last date. For example, MAX in this row would return 400,000 not 24/06/2023

Yamezz.xlsm
ABCKLMNOPQRSTUVWX
1ProductBatchCurrentNumberDateNumber2Date3Number4Date5Number6Date7Number8Date9Number10Date11Number12Date13
2Apple14X16086/03/2018400,00030/06/202229431/08/202225726/10/2022975/05/20235424/06/2023
Sheet1
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,200
Members
453,022
Latest member
RobertV1609

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