Google Sheets Conditional Formatting based on comparison between cell value - google-sheets

I thought this would've been one of the simplest ways to use conditional formatting, but apparently not.
To simplify I have two cells, B5, which derives it's value of 858 from a formula; and D2 which derives it's value of 712 from another sheet (which pulls the data from an API).
I've added conditional formatting to B5, that says "When the value of B5 is greater than the value of D2, format the cell background to green."
Or at least that's what I thought the conditional formatting rule said...
Here is a SS of the formatting rule: https://i.imgur.com/NCpl4o6.png https://i.imgur.com/sJc5Fli.png
I've found several sources online stating to use a custom formula '=B5>D2', but this does not work either. https://i.imgur.com/hBvQ7cm.png
Does anyone understand why this isn't working? and what the formatting rule I've written is actually saying?
Edit:
In case it's of any use the explicit value of B5 is '=C2*0.6'; and the explicit value of D2 is '=JSON!B2'.
If the solution involves manipulating the '*0.6' from B5, that value changes over the range I eventually want to apply the conditional formatting to.

With CF rules, everything but "Custom formula" requires literals. That is why your formulas don't work (i.e., formulas aren't literal values).
When using custom formulas, they are relative to the key cell. In your case, that is B5. So I would expect your custom formula =B5>D2 to work.
Unless...
... your D2 value is coming in formatted as a string. In that case, try the following custom CF formula:
=B5>D2*1
The addition of *1 should be enough to convert a string to a value within the formula.

Related

Why are hyphens screwing up my duplicate finding conditional formatting?

I have a sheet I use as a database of scientific papers. I copy journal article titles from different sources (some could be from an email, others are links on a web page, or just the title from the article page). I have conditional formatting set to let me know if I'm adding a title that is already in the list. I've noticed that there are some titles that are "ignoring" the conditional formatting, and it looks like there are hyphens in all of the offenders. If I remove the hyphens, the conditional formatting works. So there is some 'difference' in the hyphens originating from the same title that is preventing the conditional formatting from viewing them as identical.
Shared sheet
Examples of offending titles:
End-to-end continuous bioprocessing: impact on facility design, cost of goods and cost of development for monoclonal antibodies
End‐to‐end continuous bioprocessing: impact on facility design, cost of goods and cost of development for monoclonal antibodies
End‐to‐end continuous bioprocessing: Impact on facility design, cost of goods, and cost of development for monoclonal antibodies
What is this difference, and is there a way to fix it? Do I need to write a script to find/replace the hyphens to get this to work?
TIA
Just because characters appear identical, it does not mean that they are identical. You have fallen foul of the similarity between the hyphen and dashes. Visually, they are almost identical - dashes are slightly widest than the hyphen.
Dashes are regarded as "special characters" (i.e. they aren't keys on the keyboard) but they are used widely in html. So if, for instance, you copied an item from a website then you might unwittingly have copied dashes rather than hyphens.
You can identify the exact nature of a character by using the CODE function.
You ask "What is this difference, and is there a way to fix it? Do I need to write a script to find/replace the hyphens to get this to work?"
WHAT IS THIS DIFFERENCE?
It's important to recognise that though these examples appear identical, there are other differences that are more than just hyphens vs dashes.
Example#1 - Hyphen - CODE returns "45"
Example#2 - Dash - CODE returns "8208"
Example#3 - Dash - CODE returns "8208".
But there are other factors that contribute to fail to trigger the conditional formatting rule:
Length = 128 (vs 127 for the other examples). There is an additional comma (after "cost of sales")
the word "Impact" is spelled with an upper case "I" (lower case for the other examples)
MOVING FORWARD
Do you need a script? No (IMHO)
Is there a way to fix it? As outlined above, there are more differences that just hyphens and dashes. And, as time goes by, the number & type of difference might increase. However, there is a solution to the "Hyphen Vs Dash" problem which is the focus of this question.
FORMULA AND FORMATTING
Your data is currently in Column A and Column A is also subject to conditional formatting.
Remove the conditional formatting rules from Column A
Insert this formula in cell B2
=arrayformula(if(LEN($A2:A)-LEN(SUBSTITUTE($A2:A, char(8208), ""))=0,A2:A,arrayformula(substitute(A2:A,char(8208),char(45)))))
Conditional Formatting for Column B
select the range in Column B
select, Format, Conditional Formatting.
Select "Custom Formula is" and enter this formula: =countif($B$2:$B2,B2)>1
Select a preferred Formatting Style and then click Done.
FORMULA LOGIC
arrayformula enables the formula to automatically populate all the relevant cell in the column.
LEN($A2:A)-LEN(SUBSTITUTE($A2:A, char(8208), ""))=0
a test for dashes in a string. It substitutes a nil value for any/all instances of a dash (char(8208)), then compares the length to the adjusted length. If the value is zero, then there are no dashes in the string.
IF: Test for any dashes,
if the string doesn't contain any dashes then use that value
else, the string must contains dashes so substitute any dashes for hyphens, and use the substituted value
arrayformula(substitute(A2:A,char(8208),char(45)))
The conditional formatting rule then looks for duplicate values in the column, and formats any/all duplicate values.
You'll note that Example#3 is not flagged as a duplicate despite containing dashes. This is because of the spelling of "Impact" and the extra comma after "cost of sales".
Sample

Append check function with _Strict?

An answer in this question mentioned you can use ISDATE_STRICT in an array formula, and it worked.
I searched all over and could not find a reference to the use of _STRICT anywhere.
Does this apply to all "IS" check functions?
What exactly is it doing?
Yes, unfortunately, I also don't see any articles/documentations about this one except this.
The link above is a list of sheets formulas, we can see _STRICT on 3 formulas.
ISDATE_STRICT, ISDATETIME_STRICT, ISTIME_STRICT
The link above does answer your first question, it does not apply to all functions IS functions.
Based on their behaviors, I guess that they strictly check if the value is treated and valid as date/time/datetime in sheets itself. Simply passing string as parameter will yield FALSE.
Testing:
Note:
I have a hunch why 25:02:00 for ISTIME_STRICT is still valid for time even though it goes past 24. Sheets automatically converted that value from the inputted value 25:02 thus suggests that what sheets treats as date/time/datetime, will always yield TRUE for those functions.
To test the hypothesis above, I inputted November 31, 2021 1:00 manually and it wasn't converted into 11/31/2021 01:00:00 automatically, it was still the same cell value because it wasn't treated as datetime variable by sheets, thus returning FALSE

How to prevent Google Spreadsheet from interpreting commas as thousand separators?

Currently, pasting 112,359,1003 into Google Sheets automatically converts the value to 1123591003.
This prevents me from applying the Split text to columns option as there are no commas left to split by.
Note that my number format is set to the following (rather than being Automatic):
Selecting the Plain text option prevents the commas from being truncated but also prevents me from being able to use the inserted data in formulas.
The workaround for this is undesirable when inserting large amounts of data: select cells that you expect to occupy, set to Plain Text, paste data, set to back to desired number format.
How do I disable the automatic interpretation by Google Spreadsheet of the commas in my pasted numeric values?
You can not paste it in any number format, because of the nature of numerical format types. It will parse it into an actual number and physically store it in this format. Using plaintext type, like you are, is the way to go for this.
However, there are some options to perform these tasks in a slightly different way;
- you might be able to use CSV-import functionality, which prevents having to change types for a sheet.
- you can use int() function to parse the plaintext value into an int. (and combine this with lookup functions).
TEXT formatting:
Use ' to prepend the number. It'll be stored as text regardless of actual formatting.
Select the column and set formatting as `plain text.
In both the above cases, You can multiply the resulting text by 1 *1 to use in any formula as a number.
NUMBER formatting:
Keep Number formatting with ,/Automatic.
Here, though split text to columns might not work, You can use TEXT() or TO_TEXT()
=ARRAYFORMULA(SPLIT(TO_TEXT(A1:A5),","))

Google Sheets, formula based conditional formatting

Can custom formula based conditional formatting use NamedRanges ?
I'm experiencing that when named range is used, I cannot save the conditional formatting because formula is invalid, but when the NamedRange is replaced by a string it works. The docs do not allude to details, AFAIK.
ISNUMBER(INDIRECT("ArrivalTimes!$A$4:$S$653")) // OK
ISNUMBER(INDIRECT(RNG_ArrTimes)) // now allowed to save
Is this expected behaviour? Any docs available on this?
EDIT; based on answer for reader convenience.
AS suggested by #pnuts, it works when the range name is within double quotation marks.
However, while INDIRECT expects a string, in Sheets INDIRECT accepts NamedRanges as is without quotation marks. But, for conditional formatting, the named range must be within quotation marks. I have not found any docs that document or explain this behavior.
Can custom formula based conditional formatting use NamedRanges ?
Indeed they can.
The rest of your Q is unclear to me but perhaps it is just that you are missing double quotes around the Name of your range (and = at the beginning?).

List Comprehension in an Open Office Spreadsheet

List Comprehension is a very useful code mechanism that is found in several languages, such as Haskell, Python, and Ruby (just to name a few off the top of my head). I'm familiar with the construct.
I find myself working on an Open Office Spreadsheet and I need to do something fairly common: I want to count all of the values in a range of cells that fall between a high and low bounds. I instantly thought that list comprehension would do the trick, but I can't find anything analogous in Open Office. There is a function called "COUNTIF", and it something similar, but not quite what I need.
Is there a construct in Open Office that could be used for list comprehension?
CountIf can count values equal to one chosen. Unfortunately it seems that there is no good candidate for such function. Alternatively you can use additional column with If to display 1 or 0 if the value fits in range or not accordingly:
=If(AND({list_cell}>=MinVal; {list_cell}<=MaxVal); 1; 0)
Then only thing left is to sum up this additional column.
Assuming:
your range is A1:A10
your lower bound is at B1
your upper bound is at B2
then what you want can be achieved by:
=COUNTIFS(A1:A10, ">" & B1, A1:A10, "<" & B2)
(you might need to change commas into semicolons, depending on your language preference for decimal point)
Quoting from the installed OpenOffice documentation:
The logical relation between criteria can be defined as logical AND (conjunction). In other words, if and only if all given criteria are met, a value from the corresponding cell of the given Func_Range is taken into calculation.
This function is part of the Open Document Format for Office Applications (OpenDocument) standard Version 1.2. (ISO/IEC 26300:2-2015)

Resources