Search code examples
conditional-statementsconditional-formattingqlikviewqliksenseset-analysis

Color Coding KPI using Set Analysis and simple comparison functions (Qlik)


New Qlik Sense/ Qlik View user here.

I want to create a KPI, where the conditional coloring will filter based on two fields:

  1. EstArrivalTimeHrMinSec [Estimated time taken for an Ambulance to arrive at Incident scene (Predicted time)]

  2. TimeTakenforAmbulancetoArrive [Actual time taken for an Ambulance to arrive at Incident scene (Actual time)]

These two fields (fieldnames are in italics) are both formatted in Time('mm:ss') format for comparison, and I basically want to calculate:

  • If Actual time taken < Estimated time taken

then I want the KPI to be displayed in GREEN (actual time for the ambulance to arrive is earlier than predicted, which is GOOD).

  • If Actual time taken > Estimated time taken

then I want the KPI to be displayed in RED(actual time taken is later than predicted, which is BAD).

I have already tried creating a conditional coloring in a KPI object on my own, and here is my expression:

=If(Time(avg({$}TimeTakenforAmbulancetoArrive), 'mm:ss') < Time(avg({$}EstArrivalTimeHrMinSec), 'mm:ss'), Time(avg({$}TimeTakenforAmbulancetoArrive), 'mm:ss'), Time(avg({$}EstArrivalTimeHrMinSec), 'mm:ss'))

Sometimes the conditional coloring will work, sometimes it wouldn't, and I don't know what exactly I'm doing incorrectly with my expression. I have attached a snapshot below regarding the issue.

When the expression sometimes works (time displayed correctly as GREEN)

Time displayed Correctly

When the expression doesn't work (time should display as GREEN instead of RED)

Time displayed Incorrectly

Please help! Thanks in advance.


Solution

  • I think your expression is more complicated than it should be. The conditional color will compare the value on the KPI with the reference you add on this expression.

    If your showing the TimeTakenforAmbulancetoArrive metric, you should simply add here an expression like Time(avg({$}EstArrivalTimeHrMinSec), 'mm:ss').