Numbers: How to change cell text conditionally?
I am trying to change the text of a cell in Numbers 3 according to a condition. E.g. if A1-A2 is a negative value, the text shall be 'Negative'. If the value is positive the text shall be 'Positive'. Is there something like a function to accomplish this?
You can do this with the IF function. The syntax is…
┌── IF function returns one of two values when upon an expression's evaluation.
│
│ ┌── string or calculation for cell to show upon TRUE/FALSE
│ │ strings should be inside double quotes "like this"
│ ┌────┴─────────┐
IF(if-expression,if-true,if-false)
└─────┬─────┘
└── the expression to evaluate
for example: to test if A1-A2 is negative, you can use (A1-A2)<0
the result must be a boolean
This results in the following calculation:
IF(Data::A1<0,"Negative","Positive")
Result:
An example for comparing a calculation in the if-expression
:
┌── from table "Data" do A1-B1
│
│ ┌── is the result less than zero (i.e. negative)?
┌───────┴───────┐ │
IF((Data::A1−Data::B1)<0,"Negative","Positive")
└───┬────┘ └───┬────┘
│ └── if false, return "Positive"
│
└── if true, return "Negative"
Result:
However, this will return Positive
even if the number is 0
, so instead…
┌── from table "Data" do A1-B1
│
│ ┌── is the result less than zero (i.e. negative)?
┌───────┴───────┐ │
IF((Data::A1−Data::B1)<0,"Negative",IF((Data::A1−Data::B1)=0,"Zero","Positive"))
└───┬────┘ │ └─┬──┘ └────┬───┘
if true, return "Negative" ──┘ is equal to 0? ───┘ │ return "Positive"
└── return "Zero"