Google Sheets - Highlight cell based on another cell - google-sheets

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)

Related

Rank column with arrayformula and cull duplicates based on another column

I'm struggling with a Google Sheets arrayformula. I want to make an arrayformula to show rank position of Column B values (TOT). With my formula I just achieve a copy of the first position. I don't want duplicate values in the rank, so if there is two equal values the Column A sets the priority.
={"POS";ARRAYFORMULA(IF($B2$B:$B<>"";RANK.EQ(B3;B3:B42;0)))}
Test Document:
https://docs.google.com/spreadsheets/d/1qzs1nvpzG0VgygxbXF9bKxvGaAq-H29oI1aquupYNFc/edit?usp=sharing
If you put this in cell C2, it will rank them as you're trying to do. If you wanted to match the other direction (lowest to highest), then swith the sort parameter from false to true.
=Filter(match(B2:B+(A2:A/1000),
Sort(Filter(B2:B+A2:A/1000,B2:B<>""),1,false),0),A2:A<>"")
You also appear to have duplicates including in column A (example see rows 4,25,35). If you wanted to exclude the duplicates (effectively reducing the number of ranked values), This can be done using the unique function which would create a 17 in each row.
=Filter(match(B2:B+(A2:A/1000),
Unique(Sort(Filter(B2:B+A2:A/1000,B2:B<>""),1,false),0)),A2:A<>"")

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.

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

Implement formula in a column based on contents of each cell

In my Google Sheet, I have 1000+ rows of Date entries. For each Date, I am calculating the Month# and Week# using MONTH() and WEEKDAY() functions respectively.
Here is the link to a sample file: https://docs.google.com/spreadsheets/d/1Af5-pYMFWZ1QtLoaAbPZYMGRvk43JBslUp4KyOFADfA/edit?usp=sharing
Problem Statement:
For all rows which have a unique Month# and Week#, I would like to implement a formula and calculate Output. For example, in my sheet, rows 3 to 6 pertain to Month=1 and Week=4. For this set of 5 rows I am calculating Output column as the subtraction from the first element in that set (ie... C3-$C$3, C4-$C$3, C5-$C$3 so on ). Similarly row 7 to 10 pertain to Month=1 and Week=5, and so I calculate Output
as Data-$C$7 and so on.
How do I implement this structure to calculate Output column on each set of unique Month# and Week# values?
Delete everything from Column F (including the F2 header). Then place the following formula into cell F2:
=ArrayFormula({"Output";IF(C3:C="",,IFERROR(C3:C-VLOOKUP(E3:E,{E3:E,C3:C},2,FALSE)))})
This one formula will create the header and return results for all valid rows.
Since VLOOKUP always finds only the first matching instance of what it is looking up, we can use it to ask that each value in C3:C subtract that first instance of where week-number match for each row.
By the way, although you didn't ask about this, you can also use this type of array formula in Columns D and E, instead of all of the individual formulas you have. To do that, delete everything from Columns D and E (including the headers). Then...
Place the following formula in D2:
=ArrayFormula({"Month #";IF(B3:B="",,MONTH(B3:B))})
... and the following formula in E2:
=ArrayFormula({"Week #";IF(B3:B="",,WEEKNUM(B3:B))})

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.

Resources