Sum range in Google Sheets of only unique values - google-sheets

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

Related

How to count the number of contiguous blocks of cells, each block comprising of the same row values?

In Google Sheets, I have a sheet with a list of customers.
Row 1 has headers, and data starts in row 2.
Column A is Customer name,
Column B is street address,
Column C is City and Post Code,
Column D is Country.
I would like to count the number of occurrences of each customer's row, i.e. when A, B, C, D are the same as a composite key.
However, I want to count different occurrences of a row ONLY IF those occurrences are not adjacent / concurrent, i.e.
I do want to count separate occurrences if row 5 and 7 have the same customer,
but not if row 5 and 6 have the same customer...in this case I will count it as one occurrence
Sample sheet (Customers) with examples:
https://docs.google.com/spreadsheets/d/1J7WajZjJfl94tpgXXgk0y5ALCwG2PxoJw6poxwUyrU8/edit?usp=sharing
I have added explanations for counts in column N.
Say for example, you want to know the number of contiguous blocks whose column A value equals "O2 Arena", you can do
=countifs(FILTER(A2:A,A2:A<>A3:A),"="&A5)
It works because we want to omit rows where the value in column A is repeated in the next row. In other words, we keep those with different values than their next rows. Hence, A2:A<>A3:A.
If you want a list of counts for unique blocks, I recommend setting up the a list of the unique values first, ie. say in another sheet's A1, you have
=unique(Customers!A2:A)
then in B1, you can do
=countif(FILTER(Customers!$A$2:$A,Customers!$A$2:$A<>Customers!$A$3:$A),"="&A1)
and spread the above formula by double clicking the square on the lower right when you select B1.
The ranges in filter() should be absolute because the location of your data does not change. The range in the 2nd input of countif() should be relative because that is meant to iterate.
If values in column A does not uniquely identify your customers, you can add more columns to the input of filter() as required. For example, FILTER(A2:A,A2:A<>A3:A,B2:B<>B3:B)
For function usage, please consult official documentation by typing the function name in the search bar.

Can you use ARRAYFORMULA to SUM multiple columns changing dynamically

edit: must work with blank rows
I have a list of users in Column F and in Row 1 a list of dates.
I want to use ARRAYFORMULA to sum the values from relevant columns per each user. As an example, this sums 4 columns (F,G,H,I) per user:
=ARRAYFORMULA(IF(LEN(F1:F),G1:G+H1:H+I1:I+J1:J,""))
My question is, if it possible to sum for a dynamic number of columns. For example, I'll choose a number (e.g 7, 30...) and it will sum the relevant number of columns.
Can this be done?
Here's a spreadsheet with the above data:
https://docs.google.com/spreadsheets/d/17hyBEF1va4GMYZUFkDxxjJ0pXH2oCccgIaBT79GIsGc/edit#gid=0
In A2 I choose how many columns, and it will sum the relevant number of columns. In C1 I use such a formula to sum 4 columns using ARRAYFORMULA as an example (which is static, not dynamic).
Note that there was a nice solution, but because there is a blank row (#3) it causes the suggested solution to leave the sum for the final row (#7) empty. I'm looking for a solution that will work with blank rows.
There are 3 parameters:
A2: no of cols
G2: top left cell of values
F:F: col of row field (to count number of rows)
=ArrayFormula(MMULT(N(INDIRECT(CELL("address",G2)&":"&ADDRESS(COUNTA(F:F),COLUMN(G2)+A2-1,4))),N(TRANSPOSE(COLUMN(INDIRECT(CELL("address",G2)&":"&ADDRESS(COUNTA(F:F),COLUMN(G2)+A2-1,4)))^0))))

Combine / merge contents of columns in Google Sheet into a single column based on a condition

I have a spreadsheet with multiple columns. Each column represents a recipe. Each column has a week number (e.g. 2, 3, 4)... Below the week number, we have a variable number of ingredients. I want to be able to merge all the ingredients from a given week into a single column.
Sample Data
I know how to statically merge ranges e.g. {B4:B20;C4:C20} and I can also think of using an if statement to check the week value e.g. =if(B1=2,{B4:B20;C4:C20}) but that's not close to what I want. I need to check the range B1:Z1 for the value of the week and if that value is X (let's say 2) then take the ingredients in B2:B and tack them on to C2:C and so on...
If I'm understanding you correctly, this should do it:
=QUERY(FLATTEN(FILTER(B3:Z,B1:Z1=2)),"WHERE Col1 Is Not Null")
FILTER keeps (i.e., "filters in") only the data in B3:Z where the header is 2.
FLATTEN forms one column (blank cells and all) from the FILTER results.
QUERY keeps only non-blank (i.e., Is Not Null) entries from that single-column list.

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)

Google Sheets - Highlight cell based on another cell

I have a database with hundreds (will be thousands) of entries related to utility assets. These assets are ranked and inspected on various conditions. There are multiple inspections done periodically and the old inspection data is accessible along side the new data. I would like to use conditional formatting to highlight a cell in column Q, based on duplicate rows in column G. For example: I have one asset with an ID of 1234 in column G with 3 different inspections, and thus three entries on different rows. I want to highlight column Q if that value (in column Q) is not the same among all three inspections in the various rows. Is this something that is possible? I have tried various combinations using the =IF, =COUNTIF(S) functions. The end goal here is to recognize that column Q is not equal on all three inspections so that it can be updated to be the same value.
In the example sheet the value in column Q on row 3 does not match row's 4, 5. The value in column Q on row 7 does not match row's 6, 8, and 9. The information in all Column besides G is subject to change, so it must be based off that value.
https://docs.google.com/spreadsheets/d/1xAvRaxMii3Xijbuw3ITKo0CBPhXkW9-Bgdg_LRxv1qA/edit?usp=sharing
Logically, if there are at least as many cells with the same ID but different Q value as there are with the same ID and the same Q value, then the current cell should be highlighted:
=countifs(G:G,G3,Q:Q,"<>"&Q3)>=countifs(G:G,G3,Q:Q,Q3)

Resources