Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

problems with count

Hi There,

I am having issues  in getting the count statement

My expression is that count ({<NYEAR=mainyear>} distinct num)   . When  a filter is applied it work else it show 0 .

How can this be corrected. Please help .

regards

varghese

1 Solution

Accepted Solutions
jonathandienst
Partner - Champion III
Partner - Champion III

Hi

If mainyear is another field and you are trying to do row-by-row calculations, you cannot use a set expression, as the expression is evaluated once for the table/chart and not on every row.

You can do sum(if(NYEAR = mainyear, DISTINCT num)),

or

You can create a flag field in the load script:

     LOAD ....

          NYEAR,

          mainyear,

          If(NYEAR = mainyear, 1, 0) As YFlag,

          ....

     and then use the flag in your expression:

     Sum({<YFlag = {1}>} Distinct num)

HTH

Jonathan

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein

View solution in original post

3 Replies
jonathandienst
Partner - Champion III
Partner - Champion III

Hi

If mainyear is another field and you are trying to do row-by-row calculations, you cannot use a set expression, as the expression is evaluated once for the table/chart and not on every row.

You can do sum(if(NYEAR = mainyear, DISTINCT num)),

or

You can create a flag field in the load script:

     LOAD ....

          NYEAR,

          mainyear,

          If(NYEAR = mainyear, 1, 0) As YFlag,

          ....

     and then use the flag in your expression:

     Sum({<YFlag = {1}>} Distinct num)

HTH

Jonathan

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
Not applicable
Author

Dear Jonathan

Thanks , It worked.

regards

Varghese

Not applicable
Author

count (distinct {<NYEAR={'mainyear'}>} num)