Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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!
Hi @MPkg ,
Maybe this:
=sum( {< Value *= {"$(=if(GetSelectedCount(Value)=0,2,'*'))"} >} Value )
I hope it can help.
Best Regards
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
You can use if statements around the set analysis, but not in it.
So IF(GetSelectedCount(Value) = 0, sum({<Value={2}>}Value), sum(Value))
Hi @MPkg ,
Maybe this:
=sum( {< Value *= {"$(=if(GetSelectedCount(Value)=0,2,'*'))"} >} Value )
I hope it can help.
Best Regards
Hello Mark,
I would like to avoid IF function, because it is very slow.
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?
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.
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
Thank you both very much!
I wish you all the best!
MP