Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
zhaohaifeng
Contributor III
Contributor III

If statement performance issue

Dear all,

Now I am having the challenge in Qliksense.

Now we have some filters in the dashboard(A/B/C/D/E etc..), the requirement is that which filters we selected, for example, if field A have value 1/2/3, if we selected 1 and 2 under field A, then the field A as dimension and dimension value are 1 and 2 So we used the IF(GetSelectedCount) statement , but as the too many if statements, the performance is not good. May i know who have any ideas for my challenge? Thanks in advance.

Sameple Script:

IF(GetSelectedCount(A)>0,A,

IF(GetSelectedCount(B)>0,B,

IF(GetSelectedCount(C)>0,C,

IF(GetSelectedCount(D)>0,D,

IF(GetSelectedCount(E)>0,E,

IF(GetSelectedCount(F)>0,F,

IF(GetSelectedCount(G)>0,G,

IF(GetSelectedCount(H)>0,H,

IF(GetSelectedCount(I)>0,I,

IF(GetSelectedCount(J)>0,J,

IF(GetSelectedCount(K)>0,K,

IF(GetSelectedCount(S)>0,S,

IF(GetSelectedCount(M)>0,M,

IF(GetSelectedCount(N)>0,N,

IF(GetSelectedCount(Y)>0,Y,

IF(GetSelectedCount(X)>0,X,

IF(GetSelectedCount(Z)>0,Z,'')))))))))))))))))

Best Regards,

Haifeng

5 Replies
felipedl
Partner - Specialist III
Partner - Specialist III

Hi hafeng,

In your if statement, i'm assuming that the filters are some sort of hierarchy.

If you select only A, A values are shown, if A and B are selected, A values are shown, if H, K, S and Z are selected H values are shown.

Is that the case?

Felipe.

zhaohaifeng
Contributor III
Contributor III
Author

Correct Felipe! Any suggestions from your side?Thanks.

Best Regards,

Haifeng

felipedl
Partner - Specialist III
Partner - Specialist III

I've created this app that gets the selected fields from the hierarchy and puts it into a selection box named "Generated Field Values".

See if that helps you.

I don't have Sense installed in my machine and couldn't get the example in a QVF but basically what I did was create two variables named:

Variable Name: Expression

vX: =subfield(subfield(GetCurrentSelections(),chr(13),1),':',1)

vX2: ='$(vX)'

ANd inside a listbox use the following expression: =aggr($(vX2),$(vX2))

In that case I get in View the following:

sample.png

So the "Generated Field Values" is a list box with the top most values of the "hierarchy".

Another example:

sample.png

Hope it helps you.

Felipe.

felipedl
Partner - Specialist III
Partner - Specialist III

Forgot to mention that the dimensions need to be ordered to get this hierarchy feelling.

zhaohaifeng
Contributor III
Contributor III
Author

Thanks very much for your help Felipe!

I will try in myside.

Best Regards,

Haifeng