You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Return value from an array search in Numbers

I need to assign a filename in a Numbers table to a project based on a partial match within the filename, where:


  • Cell J3 is the filename (i.e., "Job ABC.pdf") that I want to search within
  • Lists::Search::A$3:A$440 contains parts of the filename that I want to search for (i.e., "ABC")
  • Lists::Search::B$3:B$440 contains the value I want to return when there's a match (ex: "Job 1234")


It appears that SEARCH in Numbers does not support searching an array:


This works:

SEARCH(Lists::Search::A$3, J3)


These do not:

SEARCH(Lists::Search::A$3:A$440, J3)

SEARCH("*" & Lists::Search::A$3:A$440 & "*", J3)


I started by adding individual if statements, but the array grew too large and wouldn't work with that many if statements.


Suggestions how I can get this to work properly?


Posted on Oct 8, 2024 10:46 AM

Reply
3 replies

Oct 8, 2024 8:53 PM in response to cswita

As you point out, Numbers does not support most "array" formulas.


However, it does support some. For example, it can hold the results of TEXTJOIN in memory.


Also, it supports regular expressions!


So, putting the pieces together, you can do something like this:



In K3, filled down:


=IFERROR(XLOOKUP(REGEX.EXTRACT(LOWER(J3),LOWER(TEXTJOIN("|",1,A))),A,B),"")


For the magic sauce, see Badunit's explanation in this thread (scroll up one post from the link, and consider giving it an upvote if you like as it is ingenious.) The | is an "or" in regular expression matches.


Note that in Numbers one doesn't normally use Excel-like ranges like A$3:A$440. Use A for the whole column. And you could consider putting what I am calling the Partial JobNum lookup range in a separate table.


For more on the functions used in the formula:


TEXTJOIN - Apple Support

REGEX.EXTRACT - Apple Support

XLOOKUP - Apple Support


The LOWER is simply used to convert all strings to the same case for the regular expression matching.


SG




Oct 8, 2024 8:31 PM in response to cswita

SEARCH searching within a string, not a within a range of cells. There are several lookup functions to do lookups on ranges of cells (LOOKUP, XLOOKUP, MATCH, and others) but that is the easy part of the problem. The hard part is you want to find a substring using a longer string. The lookup functions can find the string "Job ABC.pdf" if you search for it, or you can use a substring like "ABC" (along with some wildcards) to find it, but it does not work the other way around. You cannot directly look for "ABC" if you are searching for "Job ABC.pdf". But there is a way to do it.


I am assuming "Job ABC.pdf" was just a simple example and that you cannot easily isolate the "ABC" and search for only that part of the string. If you can, that would likely be far easier than the method I will give below.



Table 2 is your lookup table. No formulas except in the last row.

Last row is a footer row

Cell A8 (in the footer row) =TEXTJOIN("|",TRUE,A)


Table 1::A3 is your search word

Table 1::B3 =XLOOKUP(IFERROR(REGEX.EXTRACT(LOWER(A3),LOWER(Table 2::A$8)),"Not Found"),Table 2::A,Table 2::B,"Not Found",0)


Let me break down that formula:

  1. The string in Table 2::A$8 is for use in the REGEX.EXTRACT function. It reads as "DEF or ACD or ABC or...". It is a collection of all the substrings in the column. It becomes the search string, to see if any are in your longer "search word".
  2. The REGEX.EXTRACT function searches within your search word for any of those substrings. It needs the case to be the same so the search word and the string in Table 2 are first both converted to lowercase. If it finds one, in your search word, the result of REGEX.EXTRACT will be that substring.
  3. XLOOKUP looks that substring in Table 2::A and returns the result from Table 2::B.
  4. There are some pieces in the formula to handle cases where there was no match.


Hide the footer row in Table 2 after you have it all working.


Return value from an array search in Numbers

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.