VLOOKUP dates that fall within a range
I created a sheet to populate inspection dates by cross referencing (VLOOKUP) the license plate number from the inspection record sheet. The tracking sheet needs to populate dates within a column that represents each month (assume current year).
I was able to return dates based on this formula:
=VLOOKUP([Primary Column]@row, {Plate and Date}, 2, false)
but how do I limit the returned values to only that fall within that month?
Thanks in advance, Yael.
Best Answers
-
I would suggest an INDEX/COLLECT.
=INDEX(COLLECT({Source Sheet Date Column}, {Source Sheet Date Column}, IFERROR(MONTH(@cell), 0) = 1, {Source Sheet Plate Number Column}, [Primary Column]@row), 1)
This will restrict it to January dates. You can change the first 1 to any month number you want.
If you wanted to restrict the year as well it would look something like this (for Jan 2021)…
=INDEX(COLLECT({Source Sheet Date Column}, {Source Sheet Date Column}, AND(IFERROR(YEAR(@cell), 0) = 2021, IFERROR(MONTH(@cell), 0) = 1), {Source Sheet Plate Number Column}, [Primary Column]@row), 1)
-
I got it. Thanks so much!
Answers
-
I would suggest an INDEX/COLLECT.
=INDEX(COLLECT({Source Sheet Date Column}, {Source Sheet Date Column}, IFERROR(MONTH(@cell), 0) = 1, {Source Sheet Plate Number Column}, [Primary Column]@row), 1)
This will restrict it to January dates. You can change the first 1 to any month number you want.
If you wanted to restrict the year as well it would look something like this (for Jan 2021)…
=INDEX(COLLECT({Source Sheet Date Column}, {Source Sheet Date Column}, AND(IFERROR(YEAR(@cell), 0) = 2021, IFERROR(MONTH(@cell), 0) = 1), {Source Sheet Plate Number Column}, [Primary Column]@row), 1)
-
Thanks Paul! This worked beautifully. One more question: Is there a way I can have the return value for those that do not have an inspection date within that month to return as a blank cell rather than "#INVALID VALUE"?
-
You would use an IFERROR.
=IFERROR(INDEX(COLLECT({Source Sheet Date Column}, {Source Sheet Date Column}, AND(IFERROR(YEAR(@cell), 0) = 2021, IFERROR(MONTH(@cell), 0) = 1), {Source Sheet Plate Number Column}, [Primary Column]@row), 1), "")
-
This didn't work. I think we need another ( somewhere since we added a ) after the ""
-
Can you copy/paste the exact formula directly from the sheet to here?
-
=INDEX(COLLECT({Inspection Date}, {Inspection Date}, AND(IFERROR(YEAR(@cell), 0) = 2021, IFERROR(MONTH(@cell), 0) = 1), {Plate Number}, [Primary Column]@row), 1)
this is returning the #INVALID VLAUE response
-
If you are getting that error from that formula, double check that the error is not present in any of the referenced ranges.
-
I got it. Thanks so much!
-
Happy to help. 👍️
Help Article Resources
Categories
- All Categories
- 14 Welcome to the Community
- Smartsheet Customer Resources
- 63.5K Get Help
- 402 Global Discussions
- 213 Industry Talk
- 450 Announcements
- 4.7K Ideas & Feature Requests
- 141 Brandfolder
- 135 Just for fun
- 56 Community Job Board
- 454 Show & Tell
- 31 Member Spotlight
- 1 SmartStories
- 296 Events
- 36 Webinars
- 7.3K Forum Archives
Check out the Formula Handbook template!