Skip to main content
Announcements
Qlik Introduces a New Era of Visualization! READ ALL ABOUT IT
cancel
Showing results for 
Search instead for 
Did you mean: 
MPkg
Contributor III
Contributor III

set analysis - star equals of same field (substitution to IF function)

Hello,

I am just wondering, and I have read a lot about set analysis and did not find the answer, is it possible to get around IF function?

I have a field:

Value
1
2
3
4

 

What I want for field Value: If nothing is selected use number 2 , otherwise apply selected value.

I did not succeed to do this:

sum({<Value*={2}>}Value)

 

Is it possible to do something like this in QS?

Thanks!

Labels (1)
2 Solutions

Accepted Solutions
agigliotti
Partner - Champion
Partner - Champion

Hi @MPkg ,

Maybe this:

=sum( {< Value *= {"$(=if(GetSelectedCount(Value)=0,2,'*'))"} >} Value )

I hope it can help.

Best Regards

View solution in original post

marcus_sommer

I'm not sure if it's possible to get such a selection state just with a pure set analysis statement. The *= didn't work for your scenario because it relates to possible values which might be the selected ones respectively all possible ones if no direct selection is applied. Your conditions are excluding each other in some way - maybe there are possibilities with multiple and/or nested set analysis statements but if they are rather complex ...

In regard to your mentioned performance there is no faster approach as the from @agigliotti provided solution because the $(= ...) is an adhoc variable which is calculated before the chart is evaluated. 

- Marcus

View solution in original post

7 Replies
Mark_Little
Luminary
Luminary

You can use if statements around the set analysis, but not in it.

So IF(GetSelectedCount(Value) = 0, sum({<Value={2}>}Value), sum(Value)

agigliotti
Partner - Champion
Partner - Champion

Hi @MPkg ,

Maybe this:

=sum( {< Value *= {"$(=if(GetSelectedCount(Value)=0,2,'*'))"} >} Value )

I hope it can help.

Best Regards

MPkg
Contributor III
Contributor III
Author

Hello Mark,

I would like to avoid IF function, because it is very slow.

MPkg
Contributor III
Contributor III
Author

Hello Agigliotti,

This works thanks! I will see if this is any faster than plain IF statement.

But is there no way to do this by set expression and NOT use IF at all?

Why this:

 sum({<Value*={2}>}Value)

does not work? Is there any explanation?

agigliotti
Partner - Champion
Partner - Champion

That expression doesn't works when some value is selected (others than 2) because the * operator makes an intersection between the value 2 and the current selection.

marcus_sommer

I'm not sure if it's possible to get such a selection state just with a pure set analysis statement. The *= didn't work for your scenario because it relates to possible values which might be the selected ones respectively all possible ones if no direct selection is applied. Your conditions are excluding each other in some way - maybe there are possibilities with multiple and/or nested set analysis statements but if they are rather complex ...

In regard to your mentioned performance there is no faster approach as the from @agigliotti provided solution because the $(= ...) is an adhoc variable which is calculated before the chart is evaluated. 

- Marcus

MPkg
Contributor III
Contributor III
Author

Thank you both very much!

I wish you all the best!

MP