Categorize cells by keywords - excel-2010

I am not certain if excel can do this but I am trying to simplify the data dump that I get from twitter.
Basically what I would like to do is this:
If the tweet (in Column A) contains apple OR orange OR pear then it can be classified (in Column B) as "fruit" BUT if it has carrot OR squash OR lettuce it will be classified as "vegetable". If it has none of these then can be classified as "none"
Is this possible?
Thanks in advance.

Here is using array constant and range.
=IF(SUMPRODUCT(IF(ISERROR(SEARCH({"apple","orange","pear"},A1)),0,1))>0,"Fruit",IF(SUMPRODUCT(IF(ISERROR(SEARCH({"carrot","squash","lettuce"},A1)),0,1))>0,"Vegetable","None"))
Now for example, both fruit and vegetable are present in a string, it will always test for fruit first since that is the way the formula was arranged. (e.g. "more apple on salad than lettuce" will return "Fruit").
You can also use a range that contains your list instead of the array constant.
For example, you can put your fruit list in Column C (C1:C3) and your vegetable list in Column D (D1:D3). Your formula would then be:
=IF(SUMPRODUCT(IF(ISERROR(SEARCH(C$1:C$3,A1)),0,1))>0,"Fruit",IF(SUMPRODUCT(IF(ISERROR(SEARCH(D$1:D$3,A1)),0,1))>0,"Vegetable","None"))
But you need to enter it as Array Formula using Ctrl+Shift+Enter.
Same results and rule apply when both fruit and vegetable appear on a string. HTH.

Sure.
Try this formula
=IF(
OR(
NOT(ISERROR(SEARCH("apple",A1))),
NOT(ISERROR(SEARCH("pear",A1))),
NOT(ISERROR(SEARCH("orange",A1)))
),
"fruit",
IF(
OR(
NOT(ISERROR(SEARCH("carrot",A1))),
NOT(ISERROR(SEARCH("squash",A1))),
NOT(ISERROR(SEARCH("lettuce",A1)))
),
"veggie",
"none"
)
)

Related

Search for text within a range of cells and return Y/N

Let's say I'm collecting reviews on fruits, people submit a google form about a fruit's name (eg. "apple") and its score. This is on sheet 1. let's say the submissions of the fruit names are on col B.
On sheet 2, i have a column (lets say col A) of all fruits (apple, pear, etc)
I would like to add a column on sheet 2 (lets say col B) that asks if there is a review for that fruit. How do I do that?
Goal: select cell from col A (list of all fruits) -> search within col B on sheet 1 to see if someone submitted a review of that fruit -> if text matches, return "Y" and if it does not exist/otherwise, return "N"
Sorry if this sounds super complicated!
I tried using vlookup but i think the "range" part stumped me. also tried if and search but not sure ;-; I don't want to have to input the fruit's name manually every time. I think i'm also having trouble as it's on two different sheets (not two completely different Google Sheets, but two sheets within one Sheet. if that makes sense)
To get a true/false answer, use this formula in row 2 of a free column in Sheet2:
=arrayformula( if( len(A2:A), not(iserror(match(A2:A, 'Form Responses 1'!B2:B, 0))), iferror(1/0) ) )
But it would probably be simpler to just list all fruit and count them:
=query('Form Responses 1'!A1:C, "select B, count(B) where B is not null group by B", 1)

How to convert first letter of each word to upper case after skipping mentioned words in Google Sheet

I want to convert the first letter of all words in string except mentioned words. Direct "Proper" function will not work as it will capitalize all first letter string.
Example: "You can install it in a few clicks and it gives you a lot many options when it comes to changing case in Google Sheets."
I want to convert the above sentence to
"You can Install it in a Few Clicks and it Gives you a Lot Many Options when it Comes to Changing Case in Google Sheets."
ignored words: it, and, in, can, you, a, to
Thanks for your help in advance.
Vineet
Use regexreplace(), like this:
=lambda(
data, lowercaseWords,
byrow(
data,
lambda(
row,
mid(
reduce(
proper("_" & to_text(row)), lowercaseWords,
lambda(
acc, word,
regexreplace(acc, "(?i)\b" & word & "\b", word)
)
),
2, 9^9
)
)
)
)(
A2:A10,
{ "it", "and", "in", "can", "you", "a", "to" }
)
Give a try on the following formula-
=LAMBDA(x,TEXTJOIN(" ",1,INDEX(IF(ISERR(SEARCH(x,"it,and,in,can,you,a,to")),PROPER(x),x))))(FLATTEN(SPLIT(A1," ")))
For dynamic input range, try-
=MAP(A1:INDEX(A1:A,COUNTA(A1:A)),LAMBDA(lm,LAMBDA(x,TEXTJOIN(" ",1,INDEX(IF(ISERR(SEARCH(x,"it,and,in,can,you,a,to")),PROPER(x),x))))(lm)))
You can use a list of words you don't want to capitalize in a certain range you stablish with the next formula. Please change A1:A with your column or range and B1 with the cell of your expression:
=REDUCE(PROPER(B1),FILTER(A1:A,A1:A<>""),
LAMBDA(phrase,words,
REGEXREPLACE(phrase,""(?i)\b"&words&"\b",words)))
If you want you can use it as an arrayformula too for a whole column of phrases B1:B:
=ArrayFormula(REDUCE(PROPER(B1:B),FILTER(A1:A,A1:A<>""),
LAMBDA(phrase,words,
REGEXREPLACE(phrase,"(?i)\b"&words&"\b",words))))

How to mix and match different items to form different combination in google sheet?

Hi everyone,
I want to mix the food and drink together to form different combination. Since there are 4 type of food and 4 type of drink, which means there will be 16 types of different combination. I managed to automate the food in column F by repeating 4 times (since there are 4 type of drink) for each type of food, however, I have no idea how to automate the drink in column G to complete the 16 different combination.
When I added in new food and drink in Column B & C, ideally the new possible combination will appear in Column F & G as well.
Column I & J are the expected output that I desired. Hope to get some advice from expert. Any help will be greatly appreciated!
This is my sheet:
https://docs.google.com/spreadsheets/d/1YW5_dfCSQ4BTnA09iss3wa9dWHGDlGjqoDRJ9buMDO0/edit#gid=792268474
I have added a new sheet ("Erik Help") with the following formula in D1:
=ArrayFormula({"Food","Drink"; SPLIT(FLATTEN(FILTER(A2:A,A2:A<>"")&"|"&TRANSPOSE(FILTER(B2:B,B2:B<>""))),"|")})
This one formula creates the headers and all results in Columns D and E.
The header text can be changed within the formula as you like.
The rest just concatenates every non-null food value with a pipe symbol ("|") and a TRANSPOSEd list of every non-null drink value, forming a virtual 2D grid. That is FLATTENed into one column and then SPLIT at the pipe symbol back into two columns.
The formula will "keep up with" new food and/or drink items added (or any removed from either list). The lists need not have the same number of items either.
or:
=INDEX({FLATTEN(SPLIT(REPT(CONCATENATE(B6:B&"♦"), COUNTA(C6:C)), "♦")),
FLATTEN(SPLIT(CONCATENATE(REPT(C6:C&"♦", COUNTA(B6:B))), "♦"))})

How to join multiple cells grouped by values from a second column

I'm messing with this in Google Sheets.
I have two columns as shown in this image:
check out columns A and B picture
I would like to add a 3rd column "C", with joined values from column B depending if they are "Large", "Medium" or "Small".
For example, first cell in my desired 3rd column of joined values from my picture would be:
10,11,14
Because these values from column B match the same value on column A.
I hope I'm explaining well... I searched before posting here, but I really need a solution for that, and I think I'm missing something.
You could try something like
=TEXTJOIN(", ", 1, FILTER($B$2:$B, $A$2:$A="Large"))
or, assuming the word 'Large' is in A2:
=TEXTJOIN(", ", 1, FILTER($B$2:$B, $A$2:$A=A2))

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.

Resources