Count occurrences of words from multiple columns - google-sheets

I have a spreadsheet like this, where the values A-E are the same options coming from a form:
+------+------+------+
| Opt1 | Opt2 | Opt3 |
+------+------+------+
| A | A | B |
| B | C | A |
| C | C | B |
| A | E | C |
| D | B | E |
| B | E | D |
+------+------+------+
I want to make a ranking, showing the most chosen options for each option. I already have this, where Rank is the ranking of the option and number is the count of the option:
+------+------+------+
| Rank | Opt1 | Numb |
+------+------+------+
| 1 | A | 2 |
| 1 | B | 2 |
| 3 | C | 1 |
| 3 | D | 1 |
+------+------+------+ (I have 3 of these, one for each option)
I want to do now a summary of the 3 options, making the same ranking but joining the options. It would be something like:
+------+------+------+
| Rank |Opt123| Numb |
+------+------+------+
| 1 | B | 5 |
| 2 | A | 4 |
| 2 | C | 4 |
| 4 | E | 3 |
| 5 | D | 2 |
+------+------+------+
The easiest way to do this would be getting the data from the three ranking tables or from the original three data columns?
And how would I do this?
I already have the formula to get the names of the options, the count and ranking, but I don't know how to make them work with multiple columns.
What I have (the F column is one of the data columns):
Column B on another sheet:
=SORT(UNIQUE(FILTER('Form Responses'!F2:F;NOT(ISBLANK('Form Responses'!F2:F)))); RANK(COUNTIF('Form Responses'!F2:F; UNIQUE(FILTER('Form Responses'!F2:F;NOT(ISBLANK('Form Responses'!F2:F))))); COUNTIF('Form Responses'!F2:F; UNIQUE(FILTER('Form Responses'!F2:F;NOT(ISBLANK('Form Responses'!F2:F))))); TRUE); FALSE)
Column C:
=ArrayFormula(COUNTIF('Form Responses'!F2:F; FILTER(B2:B;NOT(ISBLANK(B2:B)))))
Column A:
=ARRAYFORMULA(SORT(RANK(FILTER(C2:C;NOT(ISBLANK(C2:C))); FILTER(C2:C;NOT(ISBLANK(C2:C))))))

Edited:
Merge cols:
=TRANSPOSE(split(join(",",D2:D,E2:E),","))
merges 2 cols, not very clean, but works. (Same as here Stacking multiple columns on to one?)
Full formula:
=SORT(UNIQUE(FILTER(TRANSPOSE(split(join(",",D2:D,E2:E),","));NOT(ISBLANK(TRANSPOSE(split(join(",",D2:D,E2:E),",")))))); RANK(COUNTIF(TRANSPOSE(split(join(",",D2:D,E2:E),",")); UNIQUE(FILTER(TRANSPOSE(split(join(",",D2:D,E2:E),","));NOT(ISBLANK(TRANSPOSE(split(join(",",D2:D,E2:E),","))))))); COUNTIF(TRANSPOSE(split(join(",",D2:D,E2:E),",")); UNIQUE(FILTER(TRANSPOSE(split(join(",",D2:D,E2:E),","));NOT(ISBLANK(TRANSPOSE(split(join(",",D2:D,E2:E),","))))))); TRUE); FALSE)
The transpose could be done after the sort.

Related

Google sheets: append data from 2 tabs, with different column order

I have 2 tabs named S1 and S2. They both contain 3 columns of data (A, B and C). I just want to merge their content in a 3rd tab, using functions. Issue is that the order of columns is different in S1 and S2.
S1
S2
S1
| Column A | Column B | Column C |
| -------- | -------- | -------- |
| 1 | A | DeptA |
| 2 | B | DeptB |
| 3 | C | DeptC |
S2
| Column A | Column B | Column C |
| -------- | -------- | -------- |
| 4 | DeptD | D |
| 5 | DeptE | E |
| 6 | DeptF | F |
What I want to get in a 3rd tab is:
| Column A | Column B | Column C |
| -------- | -------- | -------- |
| 1 | A | DeptA |
| 2 | B | DeptB |
| 3 | C | DeptC |
| 4 | D | DeptD |
| 5 | E | DeptE |
| 6 | F | DeptF |
I'm using the following formula: "query({'S1'!A1:C;'S2'!A2:A,'S2'!C2:C,'S2'!B2:B};"Select Col1, Col2,Col3 where Col1 is not null";1)". But I get a formula analysis error.
I have also tried "
={
query({S1!A1:C},"Select Col1,Col2,Col3");
query({S2!A2:C},"Select Col1,Col3,Col2")
}
"
But I also get a formula analysis error
Spreadsheet access: https://docs.google.com/spreadsheets/d/1FdaRSANfcqMkSBE-is8ek8bFWp80vVW8P3a-v0q4MwU/edit?usp=share_link
Thanks for your help
Depending on locale setting its either:
=query({{'S1'!A1:C};{'S2'!A2:A\'S2'!C2:C\'S2'!B2:B}};"Select Col1, Col2, Col3 where Col1 is not null")
OR
=query({{'S1'!A1:C};{'S2'!A2:A,'S2'!C2:C,'S2'!B2:B}},"Select Col1, Col2, Col3 where Col1 is not null")
The issue is in your Locale Settings. You should use semi-colons instead of commas:
={
query({'S1'!A1:C};"Select Col1,Col2,Col3");
query({'S2'!A2:C};"Select Col1,Col3,Col2")
}

Google Sheets - Conditional Formatting a dynamically resizing `Total` Row

I am trying to conditional format a dynamically resizing Total row of multiple tables stacked one above the other. The number of cells in the Total row may change depending upon the selection in a Year dropdown.
A | B | C | D | E | F | G | H | I | J | K | L | M |
<Year dropdown>
|Issues|2020-Jan|2020-Feb|2020-Mar|2020-Apr|2020-May|2020-Jun| | | | | | |
--------------------------------------------------------------------------------
| abc | 9 | 2 | 2 | 1 | 3 | 8 | | | | | | |
| def | 1 | 3 | 7 | 1 | 5 | 3 | | | | | | |
| ghi | 2 | 1 | 3 | 1 | 1 | 2 | | | | | | |
--------------------------------------------------------------------------------
|Total | 12 | 6 | 12 | 3 | 9 | 13 | | | | | | |
--------------------------------------------------------------------------------
I am using this formula to highlight the Total row. However, it is highlighting the entire row depending upon what range is set in the Conditional Formatting > Apply to Range box. I want to highlight only the numeric cells i.e. exclude blank cells.
=ISNUMBER(SEARCH("total",$B1))
This highlights the entire Total row including any blank cells. I modified it to exclude any blank cells in row, but no joy!
=AND(ISNUMBER(SEARCH("total",$B1)), SEARCH("total",$B1)<>""))
You can also do it like this, relying on relative addressing to modify the formula as it's effectively dragged across the formatted area:
=and(isnumber(search("Total",$B3)),B3<>"")
Use formula:
=(ISNUMBER(SEARCH("total",$B1))+(($B1:$Z1<>"")))>1

How can I count non-empty cells based on a value elsewhere in the row?

I have a table like this:
+---+---------+----------+--------+
| | A | B | C |
+---+---------+----------+--------+
| 1 | John | Judy | Team A |
| 2 | Brandon | Bethany | Team B |
| 3 | Agnes | | Team A |
| 4 | William | Welma | Team B |
| 5 | Tom | Theresa | Team B |
| 6 | Peter | | Team A |
+---+---------+----------+--------+
Counting the total number of people is easy:
=COUNTA(A1:B6) -> 10
How can I count the number of people on each of the teams? i.e., Team A is 4, Team B is 6.
You can combine COUNTA() with FILTER() to achieve this result:
=COUNTA(FILTER(A:B, C:C="Team A")) -> 4
=COUNTA(FILTER(A:B, C:C="Team B")) -> 6

Coloring cells based on numbers in string

In my sheet, on column A I have a string of numbers divided by commas. Then there are 12 numbered columns, each with its own hour. How can I shade the cells if their column's number is listed in column A?
Here is an example of what I am hoping to achieve.
| A | B | C | D | E
1 | | 1 | 2 | 3 | 4
2 | 1,2,4 | (shaded) | (shaded) | | (shaded)
3 | 2,3 | | (shaded) | (shaded) |
Select the whole range
Apply conditional fofmatting
select custom formula: =MATCH(B$1,SPLIT($A2,","),0)>0

COUNTA with FILTER using multiple conditions

I want to count the number of companies (Col B) that have a status of 'Our System' in Col A, grouped by their postcode area (e.g., SW10, SW11 etc)
As an example, the figures in the 'On System' column reflect what the formula should result in.
A | B | C | D | E | F | G |
----------|---------|----------|---|---|----------|-----------|
Status | Name | Postcode | | | Area | On System |
----------|---------|----------|---|---|----------|-----------|
On System | ABC Ltd | SW10 4ED | | | SW10 | 1 |
----------|---------|----------|---|---|----------|-----------|
On System | XYZ Ltd | SW11 5RF | | | SW11 | 2 |
----------|---------|----------|---|---|----------|-----------|
On System | GBH Ltd | SW11 5GR | | | SW12 | 0 |
----------|---------|----------|---|---|----------|-----------|
Fresh | DEF Ltd | SW11 7GG | | | SW13 | 0 |
----------|---------|----------|---|---|----------|-----------|
Fresh | GHI Ltd | SW12 5F5 | | | SW14 | 0 |
----------|---------|----------|---|---|----------|-----------|
I've used the following formula (the below example counts companies in SW10 that are 'On System'), but with no success.
=COUNTA(IFERROR(FILTER(C:C, C:C=F3&" *", A:A="On System" )))
I'm under the impression that IFERROR removes empty results or something similar. Without it, I just get a value of 1, even if there are no SW10 rows with an On System status.
Any ideas?
To count the 'on system' with postal code SW10 try:
=sumproduct(A:A="On System", regexmatch(C:C, "SW10"))
Of course you can replace the strings with cell references.
Or -shorter- use COUNTIFS() with a wildcard (*)
=countifs(A:A, "On System", C:C, "SW10*")

Resources