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

Announcements
Qlik Connect 2026! Turn data into bold moves, April 13 -15: Learn More!
cancel
Showing results for 
Search instead for 
Did you mean: 
greend21
Creator III
Creator III

Set analysis to avoid if's?

I have and expression like this:

IF(GetSelectedCount(SequenceInd)=0,

Count({$<RecOpenStatus = {'Open'}, SequenceInd = {'Seq'}>}DISTINCT ReceivableID),

    Count({$<RecOpenStatus = {'Open'}>}DISTINCT ReceivableID))

I don't think what I want to do is possible but I am hoping I am wrong and that I can increase performance. Is there another way to have my expression as Count({$<RecOpenStatus = {'Open'}, SequenceInd = {'Seq'}>}DISTINCT ReceivableID) but if another SequenceInd is selected, the result will reflect that? I am looking to reduce the IF statements in my application.

11 Replies
neelamsaroha157
Specialist II
Specialist II

Can you try this -

Count({$<SequenceInd = {$(=GetSelectedCount(SequenceInd)=0)},RecOpenStatus = {'Open'}, SequenceInd = {'Seq'}>}DISTINCT ReceivableID),Count({$<RecOpenStatus = {'Open'}>}DISTINCT ReceivableID))

greend21
Creator III
Creator III
Author

This returned null, althought I had to only use the part before the comma since using the entire thing is an invalid dimension.

For the first half, did you mean to put GetCurrentSelection instead of GetSelectedCount? I can almost see how that will work but I need it to default to 'Seq' still if possible.

Anonymous
Not applicable

You could use a variable to control the possible value of SequenceInd in your set analysis.

You would want to first create a variable; something like this:

vSeq_Selected = IF(GetFieldSelections(SequenceInd) <> 'Seq', GetFieldSelections(SequenceInd), 'Seq)

Then in your set analysis you would replace

SequenceInd = {'Seq'} With SequenceInd = {'$(vSeq_Selected)'}

Now If SequenceInd is not selected it will default to calculate it being Seq; if it is selected, it should calculate for the selected value.

trdandamudi
Master II
Master II

Neelam, I think you are missing double quotes:

Count({$<SequenceInd = {$("=GetSelectedCount(SequenceInd)=0")},RecOpenStatus = {'Open'}, SequenceInd = {'Seq'}>}DISTINCT ReceivableID),Count({$<RecOpenStatus = {'Open'}>}DISTINCT ReceivableID))

neelamsaroha157
Specialist II
Specialist II

Thanks Thirumala for pointing that out. Appreciate it. Sometimes these little things gets missed out when you are directly writing expression without the actual qv file .

greend21
Creator III
Creator III
Author

I was thinking maybe something like this, but do you know if this would improve performance at all since there is still an IF statement? I had read that IF statements can hinder performance, which seems to be the case for me so I was looking for ways to eliminate them if possible.

greend21
Creator III
Creator III
Author

This still doesn't work. I don't think qlik will take two separate measures just separated by a comma or at least it doesnt work for me.

Anonymous
Not applicable

Unfortunately, I couldn't tell you without testing. If the IF Statement you reference is an Object Expression, then I could see this solution potentially saving time because of when it's calculated.  If that IF Statement is a variable just the same as the solution I propose; it may not be.

greend21
Creator III
Creator III
Author

I was really hoping this would work so I was testing performance next to another object that had the IF statement, and if I changed the selection the object with the IF statement calculated about 2 seconds quicker than the one using the variable within the set analysis.