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

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Count if in load script

Hello,

I need to count the id field on a table only if the field type=1. I need it in the load script, but I am getting an error.

Table:

Load

If(type=1,count(id),0) as field1

sql select * from ...

Is there a way to do this?

Thank you,

Juan.

1 Solution

Accepted Solutions
hic
Former Employee
Former Employee

Count works fine in the Load script, but you need to use a Group By clause, e.g

Load

          type,

          Count(id) as field1

          Where type = 1

          Group By type

          ;

sql select * from ...

HIC

View solution in original post

4 Replies
sushil353
Master II
Master II

I not sure what are u trying to achieve from this..

but you can calculate the count of field in sql script

Load field 1;

SQL Select Count(field) as field1

where type =1;

spividori
Specialist
Specialist

Hi.

try this: if(type=1,1,0) as field1

and then in the graphics you should use count (fiel1).

Regards.

VishalWaghole
Specialist II
Specialist II

Hi

Try to set the Flag for Type = 1 like this

if(match(Type,1),'Y','N') as Type1

and then use your flag in expression like

count({<Type1 = {Y}>}Type)

Thanks.

hic
Former Employee
Former Employee

Count works fine in the Load script, but you need to use a Group By clause, e.g

Load

          type,

          Count(id) as field1

          Where type = 1

          Group By type

          ;

sql select * from ...

HIC