Skip to main content
Announcements
Accelerate Your Success: Fuel your data and AI journey with the right services, delivered by our experts. Learn More
cancel
Showing results for 
Search instead for 
Did you mean: 
tommaso26
Contributor III
Contributor III

IF Condition in Label not working

Hello everyone,

I am having some issues when using the IF condition in "Label" box in Qlik Sense.

When I use the same condition in the "Expression" box it works.

The statement is the following:

= If([Master Measure %] < 0.25, 'Class A',
   If([Master Measure %] < 0.35, 'Class B',
   If([Master Measure %] < 0.45, 'Class C',
   If([Master Measure %] < 0.55, 'Class D', 'Class E'
))))

As output I always get 'Class E'  even when the [Master Measure %] is below 0.55. If I copy paste the same above statement in the "Expression" box it returns the correct answer (i.e. 'Class C' when [Master Measure %] is below 0.55), so I believe that the problem is related to the "Label" box. Maybe because Qlik can't read the numeric condition properly.

Does anyone know how to solve this?

Thank you very much,

Tommaso

 

7 Replies
Or
MVP
MVP

What is [Master Measure %]? A column from one of your tables, or a master expression within your app? Does it always have exactly one value when evaluated in the global context (e.g. in a text box or header)?

tommaso26
Contributor III
Contributor III
Author

Hi and thank you for your answer.
[Master measure %] is a master measure that I defined within the app.

It is calculated as a percentage of quantity with respect to an overall
quantity. It has one value when evaluated globally, but it can be
aggregated and filtered by different fields.

I have no issues in using the [Master measure %] in any of the charts that
I used. I think the problem is related to the "Label" box evaluating an IF
condition.

Tommaso
Or
MVP
MVP

In that case, what happens if you just place =[Master measure %] in your label, without the surrounding If()? Does it evaluate to the expected value?

tommaso26
Contributor III
Contributor III
Author

Hi @Or,

when I put =[Master measure %] in the "Label" box without the If() condition it doesn't give the expected value. It just shows '-'

Maybe the way [Master measure %] is defined cannot be evaulated correctly within the If() condition. I still don't know how to solve this.

Or
MVP
MVP

If you are not getting a result for =[Master measure %] when used in your label box, that means it's not evaluating to a value in this context. I assume you would get the same behavior if you place it in e.g. a text box. That also explains why your if() statement won't work - the formula returns null, so you're always triggering the last Else condition in the statement.

Without knowing what the formula inside is and without knowing what the data looks like, I can't help any further - I'd suggest you pull the formula from this measure, place it directly into the label, and see if that works to return the expected value. If it doesn't, you'll need to troubleshoot the formula until it does. If using the formula directly rather than a reference to the master measure does work correctly, I'd suggest you just use that approach.

tommaso26
Contributor III
Contributor III
Author

Thank you for your answer @Or 

[Master measure %] is a measure  that evaluates the cumulative lost quantity up to a certain month with respect to the incoming quantity, it is defined as 

Aggr(RangeSum(Above(Quantity_LOST,0,RowNo())),Month)
/
Aggr(RangeSum(Above(Quantity_IN,0,RowNo())),Month)

When [Master measure %] is used in charts, it works fine and returns a percentage of lost quantity, as shown here below

tommaso26_0-1637744230048.png

So I was trying to create a Tooltip that shows the Class name at a certain month. For example, if I put my cursor on March I need to see "Class C".

Probably you are right, the way [Master measure %] is defined cannot be evaluated correctly in the Tooltip. I tried to copy/paste the formula instead of using the master measure but I always get '0' as result.

Or
MVP
MVP

Yeah, this formula won't work in this context, I think - it's only evaluated once in the label, not per dimension value.