Skip to main content
Announcements
NEW: Seamless Public Data Sharing with Qlik's New Anonymous Access Capability: TELL ME MORE!
cancel
Showing results for 
Search instead for 
Did you mean: 
wayne-a
Creator
Creator

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
sunny_talwar

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))))

View solution in original post

11 Replies
sunny_talwar

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))))

wayne-a
Creator
Creator
Author

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

sunny_talwar

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

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

wayne-a
Creator
Creator
Author

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

sunny_talwar

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?

wayne-a
Creator
Creator
Author

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.

wayne-a
Creator
Creator
Author

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

sunny_talwar

I am checking

sunny_talwar

Check the attached