Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
I am trying to set colors of the bars based on the difference between target and actual sales. but the problem I am having is that if the difference is exactly 5, the color will be blue otherwise it will show gray. even though the code says if (Avg(Targets)- (Avg([Sales])) >= 5, then set blue as the color. it only show blue when the difference is EXACLTY 5. how do i fix this?
=If(Avg(Targets)- (Avg([Sales])) >= 10, Yellow(),
If(Avg(Targets)- (Avg([Sales])) >= 15, Red(),
If(Avg(Targets)- (Avg([Sales])) >= 5, LightBlue(),
)))
average will result in a real number and not an integer and depending on how you display your data (Qlik Sense rounds it off) so depending on your precision, add fraction to force it to round up in your if statement. you will need to test this fraction (format your expression to show more decimal points so you know what you are dealing with)
also test for >=15 before testing for >=10 as it is Red will never show
hi,
you have to set between ranges as below
If(Avg(Targets)- Avg([Sales])) >= 10 and (Avg(Targets)- Avg([Sales])) <= 15, Yellow(),
ksrinivasan
Use Below Code for reference..
if( $(vActual) >=15 ,Red()
,if( $(vActual) >=10 ,Yellow()
,if( $(vActual) >= 5 ,blue()
,Black() // for all values less than 5
)
)
)
Where vActual is variable holding calculation condition
Avg(Targets)- Avg(Sales)
Also @edwin is right! Be aware of the code execution flow.