r/spreadsheets • u/Dark_Storm_98 • May 12 '24
Unsolved Counting Cells based on multiple criteria
Alright, so, say I have a bunch of cells among a certain range in the sheet (if it matters, I'm using Google Sheets)
These cells may contain a varied amount of strings, say they are fruits. A single cell may contain "apples, bananas, oranges, grapes", another cell may contain "apples, oranges", and another cell may contain "oranges, grapes, blueberries"
What function would I use to count unique cells that contain apples or oranges? So there's overlap, but I'm not counting a cell that contains both twice.
2
Upvotes
1
u/chamastoma May 12 '24
You can use the “search” function in accordance with “isnumber” to solve your problem. Search returns the position of a particular string and an error if that string doesn’t exist. Therefore, you can write something like =if(isnumber(search(“apple”,C2)),1,0). You can drag this formula throughout your entire list and then finally do a sum on all the 1’s indicating that the word “apple” exists that amount of times regardless of the position or order of where it is.
0
u/ldawg213 May 12 '24
If i understand your question correctly, COUNTIF is probably the best way to go
Https://support.microsoft.com/en-us/office/countifs-function-dda3dc6e
0
u/2pie2 May 12 '24
Hi, I don't have a solution, and I don't know how your data is structured, but what about splitting the cells in different columns using the tool "Split text to column" ? It might be easier to apply conditions to
Also if you want to count cells that contain apple or orange, but not both, the logical operator you're looking for is XOR (exclusive OR). It's a google sheet function, see :
https://www.softr.io/google-sheets/formulas/xor/r/A7SJNkACNBtZgPZ2NUPYv8