Binary search and return all matches as an array

revs92

New Member
Joined
Jul 15, 2023
Messages
7
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
Platform
  1. Windows
The last argument in XLOOKUP allows performing a binary search but XLOOKUP only returns one match.
IF(value=lookup_array,return_array,"") returns all matches in an array but is slow on large lookup ranges/does not do a binary search.

Would anyone know a fomula - or combination of - that both does a binary search on a sorted range and return all matches as an array?

Thanks in advance!
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Hi & welcome to MrExcel.
If you want to return an array of values use the FILTER function FILTER Function
 
Upvote 0
Welcome to the MrExcel Message Board!

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: Binary search and return all matches as an array
There is no need to repeat the link(s) provided above but if you have posted the question at other places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0
Hi & welcome to MrExcel.
If you want to return an array of values use the FILTER function FILTER Function
Hi Fluff, thank you for your response.
FILTER does return an array of values but it doesn't perform a binary search unfortunately/hence is too slow for my large data set.
 
Upvote 0
With that amount of data the filter function is almost instant for me, even with over a million the lag is almost unnoticeable.
 
Upvote 0
With that amount of data the filter function is almost instant for me, even with over a million the lag is almost unnoticeable.
I think you might have entered the formula in one cell. I need to enter the formula on 10,000+ rows.
 
Upvote 0
The filter formula does only go in one cell & will then spill.
 
Upvote 0
The filter formula does only go in one cell & will then spill.
I am entering the formula in 10,000+ rows because I have that number of values to report on/use as the lookup values. I then TEXTJOIN the returned arrays so they don't cause #SPILL.

I've tried thinking of a workaround, e.g. combining two XLOOKUPs with binary search, one to get the first match's index, and the second to get the last match's index, and returning the range of values between those two indices. But it does not look like XLOOKUP can both perform a binary search and return the last match. It has to be one or the other.
 
Upvote 0

Forum statistics

Threads
1,215,261
Messages
6,123,931
Members
449,134
Latest member
NickWBA

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