Qlik Community

Ask a Question

New to QlikView

If you’re new to QlikView, start with this Discussion Board and get up-to-speed quickly.

Announcements
Talk to Experts Tuesday, January 26th at 10AM EST: Qlik Sense. REGISTER NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
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
MVP & Luminary
MVP & Luminary

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

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');

View solution in original post

Creator III
Creator III

Thanks Gysbert! Yes, it is a typo.

Creator III
Creator III

Thanks Reshma! Very useful.