Intuitively I'd expected to combine FILTER, SORT and UNIQUE but I can't get them to do what I want.

IfAllElseFails

New Member
Joined
Jan 12, 2024
Messages
8
Office Version
  1. 365
Platform
  1. Windows
I want a SINGLE formula to return a SINGLE value from a table:
1) matching, in one column, a specified item
2) also, matching, in a second column, the highest date which is lower than a specified date

I can only manage it in 2 steps

I'm still getting to grips with functions which return multiple results

Help much appreciated
(sorry can't use the addin to upload a mini sheet - locked down corporate excel install)
 

Attachments

  • MR Excel Query 20240112FILTERSORTUNIQUE.PNG
    MR Excel Query 20240112FILTERSORTUNIQUE.PNG
    61.8 KB · Views: 13

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
interestingly the TAKE example didn't work correctly when I tested it with the range of dates below, equal to, and higher than the dates in the table but your one (with choosecols added) did
 
Upvote 0
MrExcelPlayground20 (version 1).xlsb
ABCDE
1ItemDateGuidance
245.029/23/2023Thing1Item45.02
345.0212/12/2022Thing2Date3/23/2023
445.021/11/2023Thing3
545.027/14/2023Thing4Thing3
665.019/23/2023Thing5
765.011/11/2023Thing6
865.017/14/2023Thing7
965.011/1/2024Thing8
1019.129/23/2023Thing9
1119.121/11/2023Thing10
Sheet24
Cell Formulas
RangeFormula
E5E5=INDEX(CHOOSECOLS(SORT(FILTER(B2:C11,A2:A11=E2),1),2),MATCH(E3,CHOOSECOLS(SORT(FILTER(B2:C11,A2:A11=E2),1),1),1))
This doesn't appear to work correctly for the higher dates - but I'm still testing.
 
Upvote 0
interestingly the TAKE example didn't work correctly when I tested it with the range of dates below, equal to, and higher than the dates in the table but your one (with choosecols added) did
Interesting indeed. I replaced the CHOOSEROWS on my suggestion with TAKE as Fluff was using it, and it seemed to work fine for me, however, I did not yet test with a different range of dates:

=TAKE(SORT(FILTER(B2:C1000,((A2:A1000=J4)*(B2:B1000<=J5))),1,-1),1,-1)
 
Upvote 1
Solution
MrExcelPlayground20 (version 1).xlsb
ABCDE
1ItemDateGuidance
245.029/23/2023Thing1Item45.02
345.0212/12/2022Thing2Date3/23/2023
445.021/11/2023Thing3
545.027/14/2023Thing4Thing3
665.019/23/2023Thing5
765.011/11/2023Thing6
865.017/14/2023Thing7
965.011/1/2024Thing8
1019.129/23/2023Thing9
1119.121/11/2023Thing10
Sheet24
Cell Formulas
RangeFormula
E5E5=INDEX(CHOOSECOLS(SORT(FILTER(B2:C11,A2:A11=E2),1),2),MATCH(E3,CHOOSECOLS(SORT(FILTER(B2:C11,A2:A11=E2),1),1),1))
Thanks James
 
Upvote 0
interestingly the TAKE example didn't work correctly when I tested it with the range of dates below, equal to, and higher than the dates in the table but your one (with choosecols added) did
There was a typo on mine, it should have been
Excel Formula:
=TAKE(SORT(FILTER(B2:C1000,(A2:A1000=J4)*(B2:B1000<=J5)),1,-1),1,-1)
 
Upvote 1
Interesting indeed. I replaced the CHOOSEROWS on my suggestion with TAKE as Fluff was using it, and it seemed to work fine for me, however, I did not yet test with a different range of dates:

=TAKE(SORT(FILTER(B2:C1000,((A2:A1000=J4)*(B2:B1000<=J5))),1,-1),1,-1)
My bad. For some reason I had C2:C1000. When I corrected it to b2:C1000 it worked
 
Upvote 0
Taking @Fluff 's suggestion into account, not to use whole columns:

Book1
ABCDEFGHIJ
1Item IDDate EffectiveGuidance
245.0223/09/2023AItem ID45.02
345.0212/12/2023BOn Date15/03/2023
445.0210/01/2023THIS
545.0214/07/2023DResultTHIS
665.0123/09/2023AA
765.0112/12/2023BB
865.0110/01/2023CC
965.0114/07/2023DD
Sheet2
Cell Formulas
RangeFormula
J5J5=FILTER(C1:C1000,(A1:A1000=$J$2)*(B1:B1000=MAX(IFERROR(B1:B1000*(B1:B1000<=$J$3)*(A1:A1000=$J$2),0))))
Thanks Felix
 
Upvote 0

Forum statistics

Threads
1,224,604
Messages
6,179,857
Members
452,948
Latest member
UsmanAli786

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