Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Congratulations to the new Qlik Luminary and Partner Ambassador class! Meet them here
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Operator as a Field Value

I have a data set that includes a value, an operator, and a threshold.  Something like the below.

ValueOperatorRed_Threshold
0.0>0.0
1.0>0.0
97.5<=100.0
99.2<95.0
5>33

I am trying to do a count where the value breaches the Red_Threshold.  I have investigated using dollar-sign expansion in set analysis, but I am unfamiliar with dollar-sign expansion so I'm having some difficulty.

Any guidance would be greatly appreciated.

Thanks!

Labels (1)
1 Solution

Accepted Solutions
marcus_sommer
MVP
MVP

I think this won't work in this way - you couldn't build an expression(part) without using $-sign expansion which meant a variable will be created which could only have one value at a time and which will be evaluated before the chart will be calculated and then applied to each row.

Therefore you need another method like these with pick(match()) - see also the attachment:

= pick(match(Operator, '>', '>=', '=', '<=', '<'),

    if(Value > Red_Threshold, 'Black', 'Red'),

    if(Value >= Red_Threshold, 'Black', 'Red'),

    if(Value = Red_Threshold, 'Black', 'Red'),

    if(Value <= Red_Threshold, 'Black', 'Red'),

    if(Value < Red_Threshold, 'Black', 'Red'))

- Marcus

View solution in original post

9 Replies
sunny_talwar
MVP
MVP

Do you have a sample app that we can take a look at?

Anonymous
Not applicable
Author

Maybe something like the attached ?

This is the Text Color expression :

     = if ( Value $(=text(Operator)) Red_Threshold , Black() , Red() )

Not applicable
Author

Hi Bill - thanks for the quick response.  This seems like the right direction, but it looks like the calculation is not working properly.  

Value Operator Red_Threshold = Value&Operator&Red_Threshold  Colour (Black is true, Red is false) Expected Colour
0.0>0.00.0>0.0Red Red
1.0>0.01.0>0.0Black Black
5>335>33Black Red  - Why is this returning Black?
97.5<=100.097.5<=100.0Black Black
99.2<95.099.2<95.0BlackRed - Why is this returning Black?

Maybe I am missing something.  Any thoughts?

marcus_sommer
MVP
MVP

I think this won't work in this way - you couldn't build an expression(part) without using $-sign expansion which meant a variable will be created which could only have one value at a time and which will be evaluated before the chart will be calculated and then applied to each row.

Therefore you need another method like these with pick(match()) - see also the attachment:

= pick(match(Operator, '>', '>=', '=', '<=', '<'),

    if(Value > Red_Threshold, 'Black', 'Red'),

    if(Value >= Red_Threshold, 'Black', 'Red'),

    if(Value = Red_Threshold, 'Black', 'Red'),

    if(Value <= Red_Threshold, 'Black', 'Red'),

    if(Value < Red_Threshold, 'Black', 'Red'))

- Marcus

Anonymous
Not applicable
Author

Marcus

Thanks for chipping in.  My way looked promising, but does not work properly.

Not applicable
Author

Thanks Marcus and Bill.

I ended up creating a breached flag  field in the script using an if statement similar to what you provided Marcus.

rwunderlich
MVP
MVP

Can you do this in the script or does it have to be done in a chart?

-Rob

Not applicable
Author

I created the flag in the script.  Basically just created a new dimension.

    if((((Red_Threshold_Operator = '>') and (Value > Effective_Red_Threshold)

  or (Red_Threshold_Operator) = '>=' and (Value >= Effective_Red_Threshold)

  or (Red_Threshold_Operator) = '<' and (Value < Effective_Red_Threshold)

  or (Red_Threshold_Operator) = '<=' and (Value <= Effective_Red_Threshold))and Effective_Red_Threshold <> ''),'Breached',

  if((((Amber_Threshold_Operator = '>') and (Value > Effective_Amber_Threshold)

  or (Amber_Threshold_Operator) = '>=' and (Value >= Effective_Amber_Threshold)

  or (Amber_Threshold_Operator) = '<' and (Value < Effective_Amber_Threshold)

  or (Amber_Threshold_Operator) = '<=' and (Value <= Effective_Amber_Threshold))and Amber_Threshold_Operator <> '')

  ,'Amber','Not Breached')) as BreachedFlag,

pretty messy but it worked for me.

rwunderlich
MVP
MVP

I was thinking of something like this:

Data:

LOAD

  *

  ,-Evaluate(Value & Operator & Red_Threshold) as Breached

;

LOAD

  Value,

    Operator,

    Red_Threshold

FROM

[https://community.qlik.com/thread/199440]

(html, codepage is 1252, embedded labels, table is @1);

-Rob

http://masterssummit.com

http://qlikviewcookbook.com