Google Sheets: Listing and counting unique values from multiple cells - google-sheets

I'm looking to list and count unique values from multiple cells. The practical application is to list and count the scenes in a movie that a particular character appears in.
I'm using the following array formula to list the scenes from the data table:
=ArrayFormula(TEXTJOIN(", ",TRUE,IF($B$11:$B$64=E13,$A$11:$A$64,"")))
It will returns something like this (these are the scene numbers):
2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4
But I want it to return:
2,3,4
Then to count the unique values I used the following formula:
COUNTUNIQUE(SPLIT(F13,", ",0))
But the problem here is that it returns "1" even when the array formula correctly returns no value (i.e. the character didn't appear in any scene)
Here is the Google Sheet so you can see things in context:
https://docs.google.com/spreadsheets/d/1dwrORFJ508duRP1no7258dqLemujkOjpvA3XmolqtsU/edit?usp=sharing
Any help will be greatly appreciated!

F11:
=ARRAYFORMULA(TEXTJOIN(",",1,UNIQUE(IF(E11=B$11:B,A$11:A,))))
=COUNT(SPLIT(F11,","))
Use UNIQUE() to find unique values before joining them
SPLIT parameter 1 can't be empty, which gives a #VALUE error,Which is counted as 1 with COUNTUNIQUE.Use IFERROR to mask it.(Since we already have unique values, COUNT is simpler)

Related

Sum range in Google Sheets of only unique values

I need a formula to sum a column of values. But I only want to sum the rows that have an ID that are unique among the entire range. See the example below where I have 6 rows, but there are only 3 unique IDs. My ideal outcome is a sum of 6 by adding one instance of UNIQUEID-00A, UNIQUEID-00B, and UNIQUEID-00C.
Notes:
A unique ID will always have the same value. For example, if UNIQUEID-00A were listed 1 or 100 times, the associated value will always be 1. So I don't need the formula to account for a scenario where the duplicate IDs have different values.
There may be instances where Column A (the ID) and Column B (the value) will not be sitting side-by-side. It might be that 2, 3, or more columns are in between the two columns.
The IDs and values could be 6 rows tall, or hundreds of rows tall. For that reason I'd like to use something like A2:A to target the IDs rather than having to specify a specific start and end point like A2:A7.
See the linked Google Sheet below for a copy of this.
ID
Value
UNIQUEID-00A
1
UNIQUEID-00B
2
UNIQUEID-00C
3
UNIQUEID-00A
1
UNIQUEID-00B
2
UNIQUEID-00C
3
https://docs.google.com/spreadsheets/d/1bU4J1RL5S0a_NvFjW_KVpiKi8603Tj9iVPeNzBlw-OA/edit?usp=sharing
Given the above table in A1:B7:
=sum(index(unique(A2:B7),,2))
UNIQUE returns the distinct rows of the range, INDEX (with column parameter = 2) to return only the value column, then SUM the result.
EDIT Based on the updated requirements, with the IDs in, for example, column A and the values to be summed in column C, use something like:
=sum(index(unique({A2:A,C2:C}),,2))
I'm assuming that there is no data below your input table. The UNIQUE here will return an extra blank row because of the unlimited range, but SUM will disregard it.
use:
=SUM(SORTN(B3:B, 9^9, 2, A3:A, 1))
sum B column
while returning all rows 9^9
that are unique 2
within A column
in whatever order 1

How to get data from concatenated strings in one cell to another table in Google Sheets?

for my use case, I have a Google survey that is connected to a main Google Sheet.
The survey has a 2 questions: 1. Name, 2. Multiple Choice from 1-31 (days of a month).
My survey results come into a by Google survey/Forms automatically generated table in Google Sheets with 2 columns: 'Name', and 'Which days?'. The 'Which Days?' column is has cells with a concatenated list of strings (e.g. '1, 3, 6, 8, 11').
The main Google Sheet has following structure: The first column is 'Name' that just imports the name from the Typeform Sheet (this works fine).
The remaining columns represent the days of the month (so up to 31 columns from 1-31).
Under each column, there are checkboxes.
The idea is that the checkboxes will automatically check according to the results from the Typeform (instead of checkboxes, we could also use colored cells if that is easier).
The problem:
How can I automatically get the data from the concatenated cell 'Which Days?' (e.g. '1, 3, 6, 8, 11') to the main Google Sheet (so that columns '1', '3', ..., '11' are checked/colored)?
Thank you!
You can use this formula on cell B2 of your main sheet (assume Sheet1 is your survey sheet and Sheet2 is your main sheet):
=IF(iferror(match(CELL("address",B2),ARRAYFORMULA(ADDRESS(ROW(B2),1+split(Sheet1!$B2,","))),0),0),TRUE,FALSE)
Then drag right and down to the end of the table.
Sample:
Explanation:
SPLIT creates an array of numbers based on your input delimited by commas.
ADDRESS creates a string of cell references. ARRAYFORMULA extends this to an array.
MATCH returns a valid value if the CELL reference of the cell position exists on the other table, else it will return error.
IF and IFERROR will return true or false depending on the value of MATCH.
use:
=ARRAYFORMULA(REGEXMATCH(COLUMN(B:K)-1&"",
"^"&SUBSTITUTE(SUBSTITUTE(IFNA(VLOOKUP(A10:A12, A1:B3, 2, 0)), " ", ), ",", "$|^")&"$"))

SUMIFs multiple criteria is not working consitently

I am using Google Sheets with the spreadsheet shown below.
I want to Sum the 'Amount' column
IF the Key in column J == the key in column B
AND The Assigned person == the actual person.
So, where the key is 2, we'd have a subset of 7 items. From that the assigned person is Sally and four entries match, our total would therefore be the sum of those matching values which are 20, 10, 2, 4 giving a sum of 36.
In K3, we can correctly see the sum of 36.
The formulae I used in that cell is:
=SUMIFS(H:H,B:B,J3,G:G,D:D)
The cell below has the formulae:
=SUMIFS(H:H,B:B,J4,G:G,D:D)
So, that should, I believe sum the values 3,8 and 4 since the key (3) in column J matches three items in column B. In each case Mike is the assigned and actual person, which means we should be summing 3, 8 and 4. However, the value as you can see is 0.
Any ideas what I'm doing wrong, please?
You can also do this with a single formula in Google Sheets;
=query(B2:H," select B,sum(H) where D=G and B is not null group by B label sum(H) ''")
Use SUMPRODUCT:
=SUMPRODUCT((B$2:B$13=J2)*(D$2:D$13=G$2:G$13)*H$2:H$13)

How to sum largest $n$ values in a range in Google Spreadsheet?

I have a list of values and I need to sum the largest 10 values (in a row). I found this but I can't figure it out/get it to work:
https://productforums.google.com/forum/#!topic/docs/A5jiMqkRLYE
let's say you want to sum the 10 highest values of the range E2:EP
then try:
=sumif(E2:P2, ">="&large(E2:P2,10))
and see if that works ?
EDIT: Maybe this is a better option ? This will only sum the 10 outputted by the array_constrain. Will only work in the new google sheets, though..
=sum(array_constrain(sort(transpose($A3:$O3), 1, 0), 10 ,1))
Can you see if this works ?
This works in old google sheets too:
sum(query(sort(transpose($A3:$O3), 1, false), "select * limit 10"))
Transpose puts the data in a column, sort sorts the data in a descending order and then query selects first 10 numbers.
Unfortunately, replacing sort with "order by" in a query statement does not work, because you can not reference a column in a range returned by transpose.
The sortn function seems to be just what you need.
From the documentation linked above, it "[r]eturns the first n items in a data set after performing a sort." The data set does not have to be sorted. It takes a bunch of optional parameters as it can sort on multiple columns.
SORTN(range, [n], [display_ties_mode], [sort_column1, is_ascending1], ...)
The interesting ones for your case are n, sort_column1, and is_ascending1. Specifically, your required formula would be
sum(sortn(transpose(A3:O3), 10, 0, 1, false)))
Some notes:
This assumes your data in A3:O3. You can replace it with your range.
transpose converts the data row to a data column as required by sortn.
10 is n, indicating the number of values that you require.
0 is the value for display_ties_mode. We are ignoring this value.
1 is the value of sort_column1, telling that we want to sort the first column (after transpose).
false tells sortn to sort descending and thus pick the largest values. The default is to pick the smallest.

Ranking Google Sheet Info Uniquely

I am trying to rank the data in one column in my google sheet so that there are no duplicate rankings. I've seen some solutions such as =RANK(A2,$A$2:$A$10)+COUNTIF($A$2:A2,A2)-1, but the problem is that it increments the duplicates based on occurrence in the sheet.
Let's say my data that I'd like ranked is as follows:
1
1
1
2
The rank order would be 2, 3, 4, 1. The problem is, if I change the second entry to 2 (so that my data is now 1, 2, 1, 2) the ranking order becomes 3, 1, 4, 2 instead of 3, 2, 4, 1 like I want. In the original data, the fourth entry was initially the highest and I'd like it to still have the higher rank, but since the formula counts occurrences it gets demoted. Any way to accomplish this?
No, not with native spreadsheet functions. Spreadsheet formulae have no "awareness" of which values were entered most recently.
You would need to resort to Google Apps Script run on an "on edit" trigger.

Resources