Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Independent validation for trusted, AI-ready data integration. See why IDC named Qlik a Leader: Read the Excerpt!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

GetSelectedCount and / or

Hi All I am currently using the following to hide/ show a table:

GetFieldSelections([Key Figure]) = 'XYZ' and GetSelectedCount(SALES_LEVEL1)>0 or GetSelectedCount(SALES_LEVEL2)>0 or GetSelectedCount([Sales Employee Name])>0 or GetSelectedCount(Account_Name)>0

This works alongside this in the alternate table:

GetFieldSelections([Key Figure]) = 'XYZ'

and GetSelectedCount(SALES_LEVEL1)=0 and GetSelectedCount(SALES_LEVEL2)=0 and GetSelectedCount([Sales Employee Name])=0  and GetSelectedCount(Account_Name)=0

HOWEVER.......

When a SALES_LEVEL is selected it appears to ignore the 'Key Figure' side of it, so I end up with 2 charts showing at the same time which is strange!!

Any ideas?

Thanks

1 Solution

Accepted Solutions
Gysbert_Wassenaar
Partner - Champion III
Partner - Champion III

You need to be explicit about the order in which the and and or's should be evaluated. Perhaps you meant something like this:


GetFieldSelections([Key Figure]) = 'XYZ' and (GetSelectedCount(SALES_LEVEL1)>0 or GetSelectedCount(SALES_LEVEL2)>0 or GetSelectedCount([Sales Employee Name])>0 or GetSelectedCount(Account_Name)>0)


talk is cheap, supply exceeds demand

View solution in original post

3 Replies
Gysbert_Wassenaar
Partner - Champion III
Partner - Champion III

You need to be explicit about the order in which the and and or's should be evaluated. Perhaps you meant something like this:


GetFieldSelections([Key Figure]) = 'XYZ' and (GetSelectedCount(SALES_LEVEL1)>0 or GetSelectedCount(SALES_LEVEL2)>0 or GetSelectedCount([Sales Employee Name])>0 or GetSelectedCount(Account_Name)>0)


talk is cheap, supply exceeds demand
Peter_Cammaert
Partner - Champion III
Partner - Champion III

The reason why Gysbert is probably right (he usually is) is that all expression operators have an order of precedence when you combine them in the same expression. That means that a multiplication will be executed before an addition, and an 'and' will be evaluated before and 'or'.

If you want to change this behavior, you should use parentheses to group subexpressions, like in he example solution above. Parentheses don't cost you anything in terms of performance or expression complexity. Better to use too many parentheses than too few.

There is a nice document about Qlik expressions here: qlik expressions.docx

See page 3 at the bottom for an operator precedence table.

However, keep in mind that this is not an official Qlik document. I couldn't even find anything like that in the official QlikView documentation (there is one for set analysis operators in the QlikView Reference manual)

Best,

Peter

Not applicable
Author

Thank you, I have the desired result!