Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
bhavvibudagam
Creator II
Creator II

count of numbers in Qlik Script

Hi Every one,

I have one Table like below

Load

Month,

Arrests,

Rating

From ...

Rating field contains the values like Positive,Negative. Now I need to calculate the count of Positive values from Rating field for each month

in the Data Model only.

Please help me how to write this calculation in scripting.

Thanks.

6 Replies
Anil_Babu_Samineni

Try this?

Abc:

Load Month, Arrests, Rating From ...

NoConcatenate

Final:

Load *, Count(Rating) as Rating Resident Abc Group By Month Where Ratings = 'Positive';

Drop Table Abc;

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
Peter_Cammaert
Partner - Champion III
Partner - Champion III

Something like this?

NewTable:

NOCONCATENATE

LOAD Month

     SUM(IF (Rating < 0, 1)) AS Negatives,

     SUM(IF (Rating > 0, 1)) AS Positives,

     SUM(IF (Rating = 0, 1)) AS Zeroes

FROM ...

GROUP BY Month;

its_anandrjs

Try to calculate this ways

Main:

Load

Month,

Arrests,

Rating

From ...

Load

Month,

Count(Rating) as RatingCount

Resident Main Where Rating >= 0

Group By Month;

its_anandrjs

What type of values in Rating field its numeric or String according to that your calculation differs.

Kushal_Chawda

Create straight table

Dimension:

Month

Expression: for positive count

=Count({<Rating ={">0"}>}Rating )

Expression: for negative count

=Count({<Rating ={"<0"}>}Rating )

andrei_delta
Partner - Creator III
Partner - Creator III

Hi,

maybe this is ok:

Tab2:

NoConcatenate

Load Month,

count(DISTINCT Rating) as Positives

Resident Tab1

Where Rating='Positive'

Group by Month;

if the field doesn't contain string values like "Positive","Negative" and it has numbers just change the where condition to:  Where Rating>=0

Hope it helps