How to Make Array Formula To Lookup Matching Values - google-sheets

As you'll see in my sample sheet, I've already found the match between two columns (C and D) and put the results in E. So these values correspond to a value from C, but are in a different order.
Now I want the values from column A, but I need for the formula to match E's value to the correct row in column C first to get the correct corresponding subject in column A.
LMK if my description needs improvement, I just rewrote it about 3 times.

I think this does what you want. There's no index function for array so you have to reconstruct a vlookup.
=filter(If(E2:E="","",vlookup(E2:E,{C:C,A:A},2,false)),not(isblank(A2:A)))

try:
=INDEX(IFNA(VLOOKUP(E2:E, {C:C, A:A}, 2, )))

Related

Arrayformula to calculate sum for each entry in a list

I need to automatically calculate the respective score of list of entries in a list. Basically I need something in the lines of "If letters in column F exist in column A, then sum for each entry in column A and if letter not found in F then return 0". It should be an array type of formula.
I tried both query function, which didn't work the way I wrote it, and arrayformula, but it doesn't give me sum per row.
=query(b3:g,"select sum (G) when F contains B group by B")
=arrayformula(sumifs(G4:G,B4:B,F4:F))
I know you can use a combination with mmult, but I don't know how to combine that with matching the column values for the letters in the list.
The file is listed below and is structured as following.
The score list in column A is fixed, and each month data in F-G column is posted, if the score is 0 for that month then the letter doesn't show up in the F column. I need an automatic way to calculate so I get the numbers in sheet 2.
https://docs.google.com/spreadsheets/d/1eyyqNL-LKw5F4kdDnbAPzN28jc4kWKMCJ-GAkn2yoXg/edit?usp=sharing
MAP() or BYROW() will do the trick. Try below formula-
=MAP(B3:B17,LAMBDA(x,SUMIFS(G3:G,F3:F,x)))
For >300 use-
=MAP(B3:B17,LAMBDA(x,SUMIFS(G3:G,F3:F,x,G3:G,">300")))
To make your input reference dynamic can use B3:INDEX(B3:B,COUNTA(B3:B)) as array argument or MAP() function. Try-
=MAP(B3:INDEX(B3:B,COUNTA(B3:B)),LAMBDA(x,SUMIFS(G3:G,F3:F,x)))

Google Sheets: Find a Row that Matches Only a Few Specific Characteristics

I can't seem to find the right equation to find a cell from a row that matches only a few specific characteristics. In this example, I am trying to find the equation for Column D which would be the cell in A that has the same cells for B & C.
Hope this makes sense!
I'll provide two options.
If you're sure your data will only ever have zero or one match, you can place the following formula into D2 of an otherwise empty range D2:D...
=ArrayFormula(IF(A2:A="",,SUBSTITUTE(VLOOKUP(B2:B&C2:C,{B2:B&C2:C,A2:A},2,FALSE)&VLOOKUP(B2:B&C2:C,SORT({B2:B&C2:C,A2:A,ROW(A2:A)},3,0),2,FALSE),A2:A,"")))
However, if you think more than one match may turn up and you want "None" to be returned if there is no match, you can use the following formula in D2 or an otherwise empty range D2:D...
=ArrayFormula(IF(A2:A="",,REGEXREPLACE(REGEXEXTRACT(REGEXREPLACE(SUBSTITUTE(VLOOKUP(B2:B&C2:C,TRIM(SPLIT(FLATTEN(QUERY(QUERY({B2:B&C2:C&"~",A2:A&","}, "Select MAX(Col2) where Col2 IS NOT NULL GROUP BY Col2 PIVOT Col1"),, 9^9)),"~")),2,FALSE),A2:A,""),"^[,\s]+$","None"),"([^,\s].+[^,\s])[,\s]*$"),"[,\s]+",", ")))
The second formula will work even if there will only ever be zero or one match; it's just not necessary to have it be that lengthy. And the second formula is only as lengthy because it was unclear from your posted examples whether the data in Col A, B and C will really only ever be one word or not; so the formula is built to assume there will not always be one-word strings in those columns.
Either formula will provide results for the entire column without dragging.
Here's an option, You can use this formula in column D2:
=iferror(textjoin(", ",true,query($A$2:$C,"Select A where A is not null and A != '"&$A2&"' and B = '"&$B2&"' and C = '"&$C2&"'",0)),"None")
Limitation:
You need to manually drag the formula to its succeeding rows. Arrayformula() cannot be used in looping the query string values.
What it does?
Using query(), filter the data from A2:C that has the same current row last name(Column B) and food(Column C) at the same time having a different first name(Column A)
If there are multiple results, use textjoin() to combine them with ", " as its delimiter.
If there is no matched found, it will return an error, hence use iferror() to set the default value to "None"
Output

Google Sheets Partial Match Cells

I am trying to do a partial match of Products (Column B) to DB (Column H). Column B however has many partial names within the cell. The entirety of Column H needs to be searched for a partial match of Column B, if a match is found then the cell name from column H needs to be input into column C.
Link to sample Google sheet: https://docs.google.com/spreadsheets/d/1ZvIbZQ9zsLd6w1uGgSbQ3v-QFebMYrlQfvdsLCfEwAg/edit?usp=sharing
Any advice on how to do this would be appreciated.
In order to look for a substring that would correspond to all the cell values from H2:H70 in B2 (and the subsequent values of the column B) you will be wanting to use the function REGEXMATCH that compares a text (in the case below B2) with a regular expressing (each of the values from H2:H70). If it finds a match then it returns the value of column H by using the IF function and if it doesnt it returns empty.
As we are comparing the range H2:H70 to B2 this will return an array of possible matches or not matches (emtpy after the IF) and therefore this array must be handled with ARRAYFORMULA.
Then we are using QUERY to only return the array values that are not empty. This will leave us with an array of values of just the actual matches found (in case there are more than one). As I imagined that you want all the matches in a single cell I am taking all the matches array values and joining them in a single array separated by a space using TEXTJOIN.
Finally, I am using IFERROR to return empty in case no matches were found.
=IFERROR(TEXTJOIN(" ",TRUE,QUERY(ARRAYFORMULA(IF(REGEXMATCH(B2, $H$1:$H$70),$H$1:$H$70,"")),"where Col1 is not null")))

Using Google Spreadsheets QUERY to Filter

I have the following google sheet where:
Col a= quantities
Col b= product codes, which i´ve split between C and H.
I want to know the quantity according to different "filters"... this filters are the fields between C11 and H11, and they are optional. There are 6 possible filters.
It works using =QUERY formula located in H12 and it returns the sum of quantity values where the filters match...
BUT there´s the possibility of leaving a filter empty to get "all"...
the query is as follows:
=QUERY(A1:H7, "select sum(A) where C contains '"&C11&"' and lower(D) contains lower('"&D11&"') and E contains '"&E11&"' and lower(F) contains lower('"&F11&"') and lower(G) contains lower('"&G11&"') and lower(H) contains lower('"&H11&"') ",-1)
My problem is with the match type: where C contains '"&C11&"' and...
instead of using "contains" it should compare using "matches". this way it would count like it should, but then it won´t accept empty filters.
How can I get it to count only if the field is filled??
What´s wrong with the filter right now? It´s counting "4" matches because model matches "1" happens when model is 1 or 21, also with column D where i´m looking for value X and is also counting value XN as it contains "X". if formula is changed to "matches" instead of "contains", it won´t allow me to leave it blank.
Thank you!
Karl_S formula is great, but it does not sum the quantities in column A. Adapting his approach to SUMIFS seems to do it:
=SUMIFS(A2:A7,C2:C7, IF(ISBLANK(C11), "<>" ,C11),D2:D7, IF(ISBLANK(D11), "<>" ,D11),E2:E7, IF(ISBLANK(E11), "<>" ,E11),F2:F7, IF(ISBLANK(F11), "<>" ,F11),G2:G7, IF(ISBLANK(G11), "<>" ,G11),H2:H7, IF(ISBLANK(H11), "<>" ,H11))
Use this formula instead:
=COUNTIFS(C2:C7, IF(ISBLANK(C11), "<>" ,C11), D2:D7, IF(ISBLANK(D11), "*",D11), E2:E7, IF(ISBLANK(E11), "<>",E11), F2:F7, IF(ISBLANK(F11), "*",F11), G2:G7, IF(ISBLANK(G11), "*",G11), H2:H7, IF(ISBLANK(H11), "*",H11))
If one of the options is blank, it will match all items in that column. Otherwise it should do an exact match.

Find matches between two columns, sum 3rd column.

I'm looking for a formula which lets me search for matches between two columns, and where a match is found, add the associated value from a 3rd column.
Example
If a fruit in column B matches any of the values in Column A, add the associated value from Column C. Here you have 2 grapefruit matches ($2) and 2 orange matches ($.5) so you get $5.
Is there a formula to do this automatically? Huge thanks for any help!
A simple version is
=sum(filter(C2:C8, match(B2:B8, A2:A4, 0)))
which looks up each element of B2:B8 in the range A2:A4, and if there is a match, includes the corresponding entry from C in the sum.
If you expect the entries in column A to grow (so they won't always stay A2:A4), the following may be preferable:
=sum(filter(C2:C8, match(B2:B8, filter(A2:A, len(A2:A)), 0)))
Here the fixed range A2:A4 is replaced by the output of a filter, which returns all nonempty cell in A2:A.

Resources