Copy link to clipboard
Copied
Hey guys. I have a query.
I have 3 fields = A, B and C
C = B/A. This is the simplified calculation for C.
Now I want C field to change its bg color to green when B is greater than A
and if B is less than A, then red.
I have tried so many things and formulae but unable to succeed, please help 😞
Copy link to clipboard
Copied
If you use simplified notation for division, you will get an error when field A is empty.
Instead, try something like this as custom calculation script of field "C":
var a = Number(this.getField("A").valueAsString);
var b = Number(this.getField("B").valueAsString);
if(!isNaN(a) && !isNaN(b) && a !== 0)
event.value = b/a;
else
event.value = "";
if((!isNaN(a) && !isNaN(b)) && (a !== 0 && b !== 0)){
if(b>a)
event.target.fillColor = color.green;
else if(b<a)
event.target.fillColor = color.red;}
else
event.target.fillColor = color.transparent;
Copy link to clipboard
Copied
If you use simplified notation for division, you will get an error when field A is empty.
Instead, try something like this as custom calculation script of field "C":
var a = Number(this.getField("A").valueAsString);
var b = Number(this.getField("B").valueAsString);
if(!isNaN(a) && !isNaN(b) && a !== 0)
event.value = b/a;
else
event.value = "";
if((!isNaN(a) && !isNaN(b)) && (a !== 0 && b !== 0)){
if(b>a)
event.target.fillColor = color.green;
else if(b<a)
event.target.fillColor = color.red;}
else
event.target.fillColor = color.transparent;
Copy link to clipboard
Copied
Thank you so much, It's perfect!