google sheet change background based on text to multiple columns - google-sheets

I learned to change background color base on cell text by column, but I need to do it column by column, does google sheets support apply a formula for multiple columns?
For example:
A B C D
1 Name v1 v2 v3
2 Apple Y Y Y
3 Orange N N Y
I can use below formula for one column:
=REGEXMATCH(B2:D3,"Y")
I try to change it to a region as below but doesn't work:
=REGEXMATCH(B2:D7,"Y")

First select range B2:D7.
Then, use this formula in Conditional formatting custom formula
=ArrayFormula(REGEXMATCH(B2:D7,"Y"))
OR put Y in text is exactly

Related

auto ranking of rows when new data is added to sheet

I have a Google sheet (sheet A) that gets fed from another sheet (sheet B). I am trying to auto-rank the rows when new data gets added to sheet B. 
In the provided example screenshot (Example below), I use a formula for the "Points" column (M). All it does is if Column L has a value of 1 then assign 7 points, if the value is 2, then assign 5 points, and if the value is 3 then assign 3 points. All others get 1 point. So every new row is added - the points are automatically assigned.
={"Points";arrayformula(IF(L2:L="",,IF(L2:L=1,7,IF(L2:L=2,5,IF(L2:L=3,3,1)))))}
The Rank column (L) uses the formula =RANK(K2, K:K).
I want a similar formula similar to points formula that ranks each of the new rows based on the Points.
I tried this formula but it does not work -
={"Rankings";arrayformula(IF(K2:K="",,IF(K2:K>1,RANK(K2, K:K))))}
Any help is appreciated.
Example Screenshot
you can try this in Column L
={"Rank";BYROW(K2:K,LAMBDA(ax,IF(ax="",,RANK(ax,K2:K))))}

Google Sheets: how to sum a dynamic range across columns using a variable to determine range length

I'm trying to write a formula in Google Sheets that will enable me to sum a range of values across columns, where I can manipulate the number of cells to be summed across the column with a variable. For example:
if my variable is 5, then I want to sum(D3:H3);
and if my variable is 9, then I want to sum(D3:L3)
Furthermore, I want a formula that I can drag across columns so that the range it's summing moves relative to the cell the formula is in. In the example above with the variable=5:
the formula in cell A3 would be sum(D3:H3);
and the formula in cell B3 would be sum(E3:I3)
etc.
I created a sample spreadsheet here for more context.
Thanks for reading!
I've added a sheet ("Erik Help"). See formula in B5:P5.
Here is the B5 formula (which was then dragged across to P5):
=ArrayFormula(SUM(FILTER($B$1:$1,COLUMN($B$1:$1)>(COLUMN()-$B$4),COLUMN($B$1:$1)<=COLUMN())))
There may be an array approach. But since you have such limited data, this is just as effective with less time investment required to develop the solution.
In plain English, the formula reads "Sum the numbers from B1:1 where the column is greater than X rows back and no greater than the current column" (where X is the value set in B4).
paste in column B and drag to the right:
=IF(COLUMN()-1<$B1, "-", SUM(INDIRECT(
ADDRESS(3, COLUMN()-($B1-1))&":"&
ADDRESS(3, COLUMN()))))

Rotate column B, C, etc values based on values in column A

I'm aware in Python pandas you can do melt to rotate cell values.
Here I want to rotate column B and C values based on column A:
Desired Result:
I need this to update on the fly as I change other values in the Google sheet, otherwise, I'd export this to a pandas dataframe and melt from there.
How can I "melt" in Google Sheets such that this rotation will update on the fly? If there's no built-in function, how would I do this in Google Sheets javascript?
Note: Transpose (=TRANSPOSE(A2:C2)) seems promising, but it doesn't pivot the table, it only moves the cell values in B and C beneath A:
=ARRAYFORMULA(TRIM(SPLIT(TRANSPOSE(SPLIT(QUERY(TRANSPOSE(QUERY(TRANSPOSE(
IF(B1:C<>"", "♠"&A1:A&"♦"&B1:C, )), , 999^99)), , 999^99), "♠")), "♦")))
Example on Sheets.
screenshot of example
Row 1 contains "hello world" "stringA" "stringB" etc. in columns A,B,C, etc.
I'm starting the output at row 3. (Outputs to columns A, B, starting on row 3.)
You can use transpose in the second column, e.g. place your transpose in B3 like this:
=TRANSPOSE(B1:1)
And then your static value for column A can be achieved with this in A3:
=ARRAYFORMULA(if(NOT(ISBLANK(B3:B)),$A$1,""))
which says to keep on eye on column B, starting at row 3, and add the static value from A1 if there is something in column B.
This dynamically grows the vertical list as you add values in row 1, and the static value follows the value of A1.
You can use the typical join split combo
=ARRAYFORMULA(SPLIT(A2&"🔺"&TRANSPOSE(B2:C2),"🔺"))
={{A1:A2,B1:B2};{A1:A2,C1:C2};{A1:A2,D1:D2}}
Add as many columns in this array. I have assumed the data to have 4 columns, with column A being the leading column.
snapshot of the data and the solution

google spreadsheet conditional formatting on a column

I have a set of data range from A to G for instance, at column G, I would like to format the cell as following
if the value of G2 is between C2 and D2, then the background color is green.
if the value of G3 is between C3 and D3, then the background color is green.
and so on for the next 500 rows
How may I do it in the latest google spreadsheet please?
Many thanks
In G2 select Conditional Formatting select custom formula and enter
=and(G2>C2,G2<D2).
Then select Apply to range and enter G2:G. It will work for all column G .
Since format the cell I assume only to apply to ColumnG. Please try selecting ColumnG and Format, Conditional formatting..., change G1: in start of Apply to range to G2: and for Format cells if... select Custom formula is and insert there:
=or(and(G2<C2;G2>D2);and(G2>C2;G2<D2))
select green fill and Done.
Change ; to , if required for your locale setting.
With text labels in Row1 it is usually simpler to select the entire column and write such a formula for Row1.

Conditional formatting based on another cell's value

I'm using Google Sheets for a daily dashboard. What I need is to change the background color of cell B5 based on the value of another cell - C5. If C5 is greater than 80% then the background color is green but if it's below, it will be amber/red.
Is this available with a Google Sheets function or do I need to insert a script?
Note: when it says "B5" in the explanation below, it actually means "B{current_row}", so for C5 it's B5, for C6 it's B6 and so on. Unless you specify $B$5 - then you refer to one specific cell.
This is supported in Google Sheets as of 2015:
https://support.google.com/drive/answer/78413#formulas
In your case, you will need to set conditional formatting on B5.
Use the "Custom formula is" option and set it to =B5>0.8*C5.
set the "Range" option to B5.
set the desired color
You can repeat this process to add more colors for the background or text or a color scale.
Even better, make a single rule apply to all rows by using ranges in "Range". Example assuming the first row is a header:
On B2 conditional formatting, set the "Custom formula is" to =B2>0.8*C2.
set the "Range" option to B2:B.
set the desired color
Will be like the previous example but works on all rows, not just row 5.
Ranges can also be used in the "Custom formula is" so you can color an entire row based on their column values.
One more example:
If you have Column from A to D, and need to highlight the whole line (e.g. from A to D) if B is "Complete", then you can do it following:
"Custom formula is": =$B:$B="Completed"
Background Color: red
Range: A:D
Of course, you can change Range to A:T if you have more columns.
If B contains "Complete", use search as following:
"Custom formula is": =search("Completed",$B:$B)
Background Color: red
Range: A:D
I've used an interesting conditional formatting in a recent file of mine and thought it would be useful to others too.
So this answer is meant for completeness to the previous ones.
It should demonstrate what this amazing feature is capable of, and especially how the $ thing works.
Example table
The color from D to G depend on the values in columns A, B and C. But the formula needs to check values that are fixed horizontally (user, start, end), and values that are fixed vertically (dates in row 1). That's where the dollar sign gets useful.
Solution
There are 2 users in the table, each with a defined color, respectively foo (blue) and bar (yellow).
We have to use the following conditional formatting rules, and apply both of them on the same range (D2:G3):
=AND($A2="foo", D$1>=$B2, D$1<=$C2)
=AND($A2="bar", D$1>=$B2, D$1<=$C2)
In English, the condition means:
User is name, and date of current cell is after start and before end
Notice how the only thing that changes between the 2 formulas, is the name of the user. This makes it really easy to reuse with many other users!
Explanations
Important: Variable rows and columns are relative to the start of the range. But fixed values are not affected.
It is easy to get confused with relative positions. In this example, if we had used the range D1:G3 instead of D2:G3, the color formatting would be shifted 1 row up.
To avoid that, remember that the value for variable rows and columns should correspond to the start of the containing range.
In this example, the range that contains colors is D2:G3, so the start is D2.
User, start, and end vary with rows
-> Fixed columns A B C, variable rows starting at 2: $A2, $B2, $C2
Dates vary with columns
-> Variable columns starting at D, fixed row 1: D$1
Basically all you need to do is add $ as prefix at column letter and row number. Please see image below
change the background color of cell B5 based on the value of another cell - C5. If C5 is greater than 80% then the background color is green but if it's below, it will be amber/red.
There is no mention that B5 contains any value so assuming 80% is .8 formatted as percentage without decimals and blank counts as "below":
Select B5, colour "amber/red" with standard fill then Format - Conditional formatting..., Custom formula is and:
=C5>0.8
with green fill and Done.
I'm disappointed at how long it took to work this out.
I want to see which values in my range are outside standard deviation.
Add the standard deviation calc to a cell somewhere =STDEV(L3:L32)*2
Select the range to be highlighted, right click, conditional formatting
Pick Format Cells if Greater than
In the Value or Formula box type =$L$32 (whatever cell your stdev is in)
I couldn't work out how to put the STDEv inline. I tried many things with unexpected results.
I just want to explain it in a another way. In "custom formula" conditional formatting you have two important fields:
Custom formula
Apply to
Let's say, you have a simple sheet with test percentages of students, where you want to color Student Ids(Column B) where their score(Column C) > 80%:
Row
B(Student ID)
C(Score)
1
48189
98%
2
9823
6%
3
17570
40%
4
60968
23%
5
69936
7%
6
8276
59%
7
15682
96%
8
95977
31%
To design a custom formula, you only need to design a formula for the top left of the range, you want to color. In this case, that would be B1.
The formula should return
TRUE, if it should be colored and
FALSE, if it shouldn't be colored
For B1, the formula would then be:
=C1>80%
Now imagine that you put that formula in B1(Or just use a another range to test it). It would be like:
Row
B
C
1
TRUE
2
3
4
5
6
7
8
Now imagine dragging the formula(or autofill) up to B8 from B1. This is how it would look like
Row
B
C
1
TRUE
2
FALSE
3
FALSE
4
FALSE
5
FALSE
6
FALSE
7
TRUE
8
FALSE
This translates directly to color B1 and B7. Now the interesting thing is All of this is autocalculated using the given formula for B1 and the Apply to range. If you fill:
Custom formula: =C1>80% and
Apply to: B1:B8
you're saying
Fill the custom formula =C1>80%
in the top left cell of the provided range B1:B8,i.e., B1 and
drag/autofill the formula to the whole range B1:B8 and
Color the cells, where the formula outputs TRUE
If you want to color both student IDs and score, you would use
Custom formula:
=$C1>80%
Apply to:
B1:C8
The $ in the $C1 says not to change C, when autofilling the range. In the imaginary table(I suggest you to output the table somewhere). This would look like:
Row
B
C
1
TRUE
TRUE
2
FALSE
FALSE
3
FALSE
FALSE
4
FALSE
FALSE
5
FALSE
FALSE
6
FALSE
FALSE
7
TRUE
TRUE
8
FALSE
FALSE
In this way, you can color any cell anywhere based on any other cell.

Resources