Reputation: 21
I'm trying to count the number of times either of two cells is not empty/not blank where another cell in the same row contains a specific string.
Table1 (input data)
| Got | Location | Name | Coords 1 | Coords 2 |
| TRUE | Fridge | Milk | | (5341, 3258) |
| FALSE | Fridge | Egg | | |
| FALSE | Fridge | Bread | (5356, 3128) | |
| TRUE | Fridge | Cheese | | |
Table2 (ideal formula output)
| Location | Total Got | Total There | Total With Coords |
| Fridge | 2 | 4 | 2 |
Table2 (less than ideal formula output)
| Location | Total Got | Total There | Total Coords 1 | Total Coords 2 |
| Fridge | 2 | 4 | 1 | 1 |
So the ideal answer I'm trying to get for table 2 column D would be 2, because there are two rows in which either of the coords columns are not empty.
I am able to count the number of items that have been looted from the fridge by using =COUNTIFS(Table1!A:A, true,Table1!B:B,A2), so I thought I could say something like =COUNTIFS(Table1!D:D, <>"",Table1!B:B,A2) or =COUNTIFS(Table1!D:D, <>null,Table1!B:B,A2) but those didn't work. =DCOUNTA(Table1!C:E,1,<>"") and =DCOUNTA(Table1!C:E,1,<>null) return errors as well even before I try checking for location.
I don't remember much about SQL, so it's no surprise that =QUERY(Table1!A:E,"SELECT COUNT(D) WHERE D!='' AND B='Fridge'",0) failed. I also couldn't figure out how to make the second term use a value from the table I'm displaying the data, and the output takes up two cells in different rows.
=ARRAYFORMULA(SUM(N(REGEXMATCH(Table1!D2:D, " ")))) counts the right number of coords in the column, but i have no idea what's going on here or how to make it count multiple columns, or the location.
Upvotes: 1
Views: 21
Reputation: 21
Turns out that instead of thinking outside the box, I had to think outside the cell. I added a column to Table1 that checks both columns for a value in either column and returns true or false. =IFS(D2<>"", true,E2<>"", true) works for this.
| Got | Location | Name | Coords 1 | Coords 2 | AnyCoords |
| TRUE | Fridge | Milk | | (5341, 3258) | TRUE |
| FALSE | Fridge | Egg | | | FALSE |
| FALSE | Fridge | Bread | (5356, 3128) | | TRUE |
| TRUE | Fridge | Cheese | | | FALSE |
And then I solve the initial problem by counting true values in the new column using the formula =COUNTIFS(Table1!F:F, true,Table1!B:B,A2).
I am posting and answering my own question quite rapidly, because the thing is, I could not find this answer on Google or via Stack Overflow search, and it took me several hours to figure out any answer (while writing the question) so hopefully this makes it easier to find in the future. I'm really quite frustrated and have a headache now.
Upvotes: 1