Return Code for a certain ID in a date Range

murrolems

New Member
Joined
Jun 5, 2024
Messages
7
Office Version
  1. 365
Platform
  1. Windows
I have the following data in 3 columns: ID, date and code. I need a formula that will return the code for a given ID and a random date that falls within a range. The date field could be sorted by ID first then date if necessary.

Table:
IDDateCode
1​
5/23/2024​
F
1​
5/8/2024​
E
1​
4/29/2024​
C
3​
5/23/2024​
S
3​
5/23/2024​
H
2​
5/8/2024​
E
2​
4/23/2024​
K
2​
5/23/2024​
X
4​
5/8/2024​
P

Here's an example of the desired output:

IDrandom datereturned code
1​
5/7/2024​
C
1​
5/8/2024​
E
1​
5/9/2024​
E
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
I didn't mean for ID 3 to have the same date, this is just an example table. The actual data won't have the same dates duplicated for an ID
 
Upvote 0
Try:
Book1
ABCDEFG
1IDDateCodeIDrandom datereturned code
215/23/24F15/7/24C
315/8/24E15/8/24E
414/29/24C15/9/24E
535/23/24S
635/23/24H
725/8/24E
824/23/24K
925/23/24X
1045/8/24P
Sheet1
Cell Formulas
RangeFormula
G2:G4G2=XLOOKUP(F2,IF($A$2:$A$10=E2,$B$2:$B$10),$C$2:$C$10,,-1)
 
Upvote 0
Solution
Try:
Book1
ABCDEFG
1IDDateCodeIDrandom datereturned code
215/23/24F15/7/24C
315/8/24E15/8/24E
414/29/24C15/9/24E
535/23/24S
635/23/24H
725/8/24E
824/23/24K
925/23/24X
1045/8/24P
Sheet1
Cell Formulas
RangeFormula
G2:G4G2=XLOOKUP(F2,IF($A$2:$A$10=E2,$B$2:$B$10),$C$2:$C$10,,-1)
Thank you for the reply! Can I use that formula for Google sheets? I didn't think it had an xlookup function.
 
Upvote 0
This is the wrong sub-forum for Sheets, but it does have XLOOKUP. However, I don't know how arrays behave in Sheets.
 
Upvote 0
This is the wrong sub-forum for Sheets, but it does have XLOOKUP. However, I don't know how arrays behave in Sheets.
Thanks again, this formula fails for any dates that come before the furthest out date. For example, if I'm looking for 4/7/24, I get an error because it is before the date range. Any ideas?

IDgiven datereturned code
1​
4/7/2024​
#N/A​
1​
5/8/2024​
E
1​
5/9/2024​
E
 
Upvote 0
As I mentioned, I don't know how arrays behave in Sheets so can't help.
 
Upvote 0
In Exccel, I am not getting #N/A.
Book1 (version 1).xlsb
ABCDEFG
1IDDateCodeIDrandom datereturned code
215/23/2024F14/7/2024C
315/8/2024E15/8/2024E
414/29/2024C15/9/2024E
535/23/2024S
635/23/2024H
725/8/2024E
824/23/2024K
925/23/2024X
1045/8/2024P
Sheet2
Cell Formulas
RangeFormula
G2:G4G2=XLOOKUP(F2,IF($A$2:$A$10=E2,$B$2:$B$10),$C$2:$C$10,,-1)
 
Upvote 0
In Exccel, I am not getting #N/A.
Book1 (version 1).xlsb
ABCDEFG
1IDDateCodeIDrandom datereturned code
215/23/2024F14/7/2024C
315/8/2024E15/8/2024E
414/29/2024C15/9/2024E
535/23/2024S
635/23/2024H
725/8/2024E
824/23/2024K
925/23/2024X
1045/8/2024P
Sheet2
Cell Formulas
RangeFormula
G2:G4G2=XLOOKUP(F2,IF($A$2:$A$10=E2,$B$2:$B$10),$C$2:$C$10,,-1)
Hmm, that's weird. I do get #N/A in excel, here is a screenshot from my excel. I included the evaluate where you can see it's doing a lookup that fails.
1717695984656.png
 
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,165
Members
453,021
Latest member
Justyna P

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