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

Count function in variable

Hello all,

Happy Friday! Could someone please explain how can I use Count function in a variable. For example, I want to count the number of questions where Answer=Yes + Answer=No/Total Answer in percentage. Something like below.

vTotal=Count(Answer=Yes+No)/Count(Answers), #.##%

I tried below in the load script but it may not have worked because with

SET vTotal=count({<Answer={'Yes', 'No'}> Answers}/count(Answer)

It didn't work...perhaps set analysis syntax cannot be used in load script.

Any help is appreciated.

1 Solution

Accepted Solutions
Not applicable

Hi,

You can try this at script lever as

Table1:

load count(if(Answer='YES'or Answer='NO',1,0))/Count(Answer) as x

from xxx

group by Answer;

vTotal=peek('x',-1,'Table1');

View solution in original post

5 Replies
Gysbert_Wassenaar

That's right, set analysis cannot be used in the script. But creating a variable with a set analysis expression will work fine. But make sure to use the exact case sensitive field names. Answers and Answer are two different field names. Perhaps you simply made a typo:

SET vTotal=count({<Answer={'Yes', 'No'}> Answers}/count(Answer)


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

Take a look at my example

Not applicable

Hi,

You can try this at script lever as

Table1:

load count(if(Answer='YES'or Answer='NO',1,0))/Count(Answer) as x

from xxx

group by Answer;

vTotal=peek('x',-1,'Table1');

infock12
Creator III
Creator III
Author

Thanks Gysbert! Yes, it is a typo.

infock12
Creator III
Creator III
Author

Thanks Reshma! Very useful.