Announcements
cancel
Showing results for
Did you mean:
Partner - Contributor II

## If condition: compare strings without single quotes

Hi all,

Is there a way to write a comparison between a variable and a string in an IF-condition without single quotes '  ' ?

E.g. IF('\$(vCondition)' = 'A', Field1, Field2)

Some background of why I need this. I have been trying to implement the second solution written in this article. I have a graph that should show a certain measure from a list of calculation-intensive measures based on a condition. As we know, if you place multiple measures within an IF-condition, it will first calculate all the measures, and then provide the result, which makes the app slower and less repsonsive.

As you can see, for this we need our measures to be between single quotes.

In my case, I have something like this:
=if(vSelectMeasure=1,
'sum(IF('\$(vCondition)' = 'A', Field1, Field2))',
'count(IF('\$(vCondition)' = 'A', Field1, Field2))')

In this formula, we have single quotes to show which measure to use (outer-quotes), and within each measure, other single quotes to compare the condition with a string. These latter single quotes will make this fail as Qlik will think it represents the end of the first outer-quotes.

I have already tried multiple solutions not to have single quotes inside this formula, without success:

• Tried to put double quotes here "\$(vCondition)" = "A" or on the outside quotes
• Tried to use chr(39) : IF( chr(39)&\$(vCondition)&chr(39) = chr(39)&A&chr(39), Field1, Field2)
• This provides a strange result as it returns True for any value of vCondition, so it's not comparing.
• Tried to put this condition in another variable (with and without an = sign before), but Qlik still reads this variable and stops at the first single quote.
• Tried with pick(match()), but it behaves the same as IF.
• Tried with the replace() function to replace a certain character with chr(39), but in there we still need to use single quotes around the special chars.

Do you have an idea of what else I could try to solve this?

Labels (7)

• ### String

4 Replies
Partner - Specialist III

Hi,

Maybe this will work:

=if(vSelectMeasure=1,
'sum(IF(' & chr(39) & '\$(vCondition)' & chr(39) & ' = ' & chr(39) & 'A' & chr(39) & ', Field1, Field2))',
'count(IF(' & chr(39) & '\$(vCondition)' & chr(39) & ' = ' & chr(39) & 'A' & chr(39) & ', Field1, Field2))')

Partner - Contributor II
Author

Hi, thanks for your suggestion, but that didn't work.

The single quotes '  ' are still being interpreted as the end of the outer-quotes in this formula.

Partner - Specialist III

What is the content of vCondition variable?

Partner - Contributor II
Author

The vCondition variable contains a string value (A, B, C, ...) that is being modified by the extension 'Variable input'. Therefore, it contains no calculations.