Qlik Community

New to Qlik Sense

Discussion board where members can get started with Qlik Sense.

paolo_mapelli
Contributor

Expression with boolean variable in set analysis

Good Morning,

I've a simple expression like this: Sum(if($(bCondition),Adults))

$(bCondition) is a boolean variable.


How can I "translate" it correctly in set analysis syntax ?

Thanks in advance.

Paolo.

1 Solution

Accepted Solutions
rahulpawarb
Valued Contributor III

Re: Expression with boolean variable in set analysis

I 100% agree with Chanty! While loading the data create a flag field with definition of $(bCondition) i.e. 1 or 0; later you can consume it in set expression as Sum({<flag={1}>}Adults).


Regards!

Rahul Pawar

13 Replies
agigliotti
Honored Contributor II

Re: Expression with boolean variable in set analysis

how your bCondition variable looks like ?

Chanty4u
Esteemed Contributor III

Re: Expression with boolean variable in set analysis

try with single quotes

Sum(if('$(bCondition)',Adults))

paolo_mapelli
Contributor

Re: Expression with boolean variable in set analysis

It's a (very complex) boolean expression, that I don't want to replicate with set analysis syntax...

paolo_mapelli
Contributor

Re: Expression with boolean variable in set analysis

That's not set analysis syntax...

Chanty4u
Esteemed Contributor III

Re: Expression with boolean variable in set analysis

if you want to create set ,

create a flag for bCondition     value inside it and use that in frontend set analysis


agigliotti
Honored Contributor II

Re: Expression with boolean variable in set analysis

i guess you can't.

why are you thinking to use set analysis ?

i think you should rewrite the boolean variable logic inside the script adding a new field, after you can use it in set analysis.

paolo_mapelli
Contributor

Re: Expression with boolean variable in set analysis

Because lot of people told me that "if" lacks on performance, so I'm evaluating how to convert these expressions with set analysis.


An alternative would be convert them and store expressions into variables, then use them.


Example: let's say $(bCondition) is something taking everything that current selection excludes, built with "if" and other script functions. In set analysis it's intended as {1-$}. <pseudo-syntax mode on> So: LET bCondition = "{1-$}". Then: sum(<$(bCondition)>Adults) </pseudo-syntax mode off>


But I don't think it's an available way...




Chanty4u
Esteemed Contributor III

Re: Expression with boolean variable in set analysis

yes, you are correct,

but one or two if doesn't make any issue i believe ,  if it is complex and multiple if conditions if you use in front end it causes performance issue.

read this

If statement vs Set analysis

rahulpawarb
Valued Contributor III

Re: Expression with boolean variable in set analysis

I 100% agree with Chanty! While loading the data create a flag field with definition of $(bCondition) i.e. 1 or 0; later you can consume it in set expression as Sum({<flag={1}>}Adults).


Regards!

Rahul Pawar

Community Browser