Qlik Community

Qlik Sense App Development

Discussion board where members can learn more about Qlik Sense App Development and Usage.

wayneantinore-a
Contributor

Set analysis with dynamic variable

Hi, I've been trying to get a set analysis expression working with a variable without any luck.  My variable value is set dynamically depending on selection(s) of a dimension.  Definition is as follows:

If(GetSelectedCount(Test_ID)<> 1,('SYP' &  ',' & 'RPR'),

      If(MixMatch(GetFieldSelections(Test_ID),'SYP'),('SYP'),

      If(MixMatch(GetFieldSelections(Test_ID),'RPR'),('RPR'),('SYP' &  ',' & 'RPR'))))

When I put this value in a KPI it displays as SYP,RPR but if I use it in a set analysis expression like the following it doesn't apply and shows up as a - in the kpi

=Count({$<Positive = {'Y'},Test_ID={$(=vSYPRPR)}>}[Order#])

If I define the variable like the following then the correct values are returned

='SYP,RPR'

Is it not possible to use a dynamically defined variable in set analysis?  I've looked up lots of examples of using variables in set analysis and tried the various examples I've seen on the community but have not been able to get this to work.

Thanks in advance for any help or insight.

1 Solution

Accepted Solutions
MVP
MVP

Re: Set analysis with dynamic variable

May be try this

If(GetSelectedCount(Test_ID)<> 1, Chr(39) & 'SYP' & Chr(39) &  ',' & Chr(39) &  'RPR' & Chr(39),

      If(MixMatch(GetFieldSelections(Test_ID),'SYP'), Chr(39) & 'SYP' & Chr(39),

      If(MixMatch(GetFieldSelections(Test_ID),'RPR'), Chr(39) & 'RPR' & Chr(39), Chr(39) & 'SYP' & Chr(39) &  ',' & Chr(39) &  'RPR' & Chr(39))))

11 Replies
MVP
MVP

Re: Set analysis with dynamic variable

May be try this

If(GetSelectedCount(Test_ID)<> 1, Chr(39) & 'SYP' & Chr(39) &  ',' & Chr(39) &  'RPR' & Chr(39),

      If(MixMatch(GetFieldSelections(Test_ID),'SYP'), Chr(39) & 'SYP' & Chr(39),

      If(MixMatch(GetFieldSelections(Test_ID),'RPR'), Chr(39) & 'RPR' & Chr(39), Chr(39) & 'SYP' & Chr(39) &  ',' & Chr(39) &  'RPR' & Chr(39))))

wayneantinore-a
Contributor

Re: Set analysis with dynamic variable

Hi Sunny,

Thank you for the reply.  When I do that the variable in the KPI looks ok with the quotes around the individual values but in the count expression it doesn't evaluate coming back with a value of -

I tried something similar by concatenating the quotes and received the same results. 

('''SYP''' &  ',' & '''RPR''')

Wayne

MVP
MVP

Re: Set analysis with dynamic variable

Try removing the = from your set analysis and see if that works

=Count({$<Positive = {'Y'}, Test_ID = {$(vSYPRPR)}>} [Order#])

wayneantinore-a
Contributor

Re: Set analysis with dynamic variable

Hi Sunny,

Unfortunately same result.  Here is the changed statement just to verify I didn't do something wrong.

=Count({$<Positive = {'Y'},Test_ID={$(vSYPCH39)}>}[Order#])

Thanks,

  Wayne

MVP
MVP

Re: Set analysis with dynamic variable

So, just so we are on the same page... you used the new expression I gave for your variable and used the above expression without = sign and still didn't get anything? Would you be able to share a sample to check this?

wayneantinore-a
Contributor

Re: Set analysis with dynamic variable

Hi Sunny,

No worries.  Yes, I created a new variable called vSYPCH39 and copied the definition you supplied as follows:

If(GetSelectedCount(Test_ID)<> 1, Chr(39) & 'SYP' & Chr(39) &  ',' & Chr(39) &  'RPR' & Chr(39),

      If(MixMatch(GetFieldSelections(Test_ID),'SYP'), Chr(39) & 'SYP' & Chr(39),

      If(MixMatch(GetFieldSelections(Test_ID),'RPR'), Chr(39) & 'RPR' & Chr(39), Chr(39) & 'SYP' & Chr(39) &  ',' & Chr(39) &  'RPR' & Chr(39))))

And the expression is the following:

=Count({$<Positive = {'Y'},Test_ID={$(vSYPCH39)}>}[Order#])

I'll see if I can get a small app together, it has a lot of data.

wayneantinore-a
Contributor

Re: Set analysis with dynamic variable

Hi Sunny,

I attached an example to my post above.  There is a KPI with a value of "-" that is using the variable and expression from the post above.

Thanks again for your help.

Wayne

MVP
MVP

Re: Set analysis with dynamic variable

I am checking

MVP
MVP

Re: Set analysis with dynamic variable

Check the attached

Community Browser