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

Count with set analysis

Hello,

I´ve 2 tables like:

TABLE_1

PK,

CODIGO,

NR_ANO,

NR_MES

TABLE_2

PK,

NR_ANO_INICIO_COMPETENCIA,

NR_MES_INICIO_COMPETENCIA

I need count CODIGO while NR_ANO = NR_ANO_INICIO_COMPETENCIA.

I´m using this expression:

=Count({$<NR_ANO = NR_ANO_INICIO_COMPETENCIA>} DISTINCT CODIGO)   but isn´t  work.

1 Solution

Accepted Solutions
swuehl
MVP
MVP

Well, I still think that

=Count({$<NR_ANO = {"=NR_ANO=NR_ANO_INICIO_COMPETENCIA"} >} DISTINCT CODIGO)

should work. It's hard to help you if you don't give some more information...

If it's about performance, a distinct count on large data volume is probably always performing not very well.

You could try some of the methods e.g. described in the manual to improve performance on distinct counts.

For example, you could create a new table

LOAD DISTINCT

CODIGO, 1 as CODIGO_DIST

resident TABLE_1;

then do a sum( .... CODIGO_DIST) instead of the count( distinct .... CODIGO)

View solution in original post

6 Replies
swuehl
MVP
MVP

This will only work if you select on NR_ANO_INICIO_COMPETENCIA.

Try this:

=Count({$<NR_ANO = p(NR_ANO_INICIO_COMPETENCIA) >} DISTINCT CODIGO)  

Or do you need a record based comparison on these two fields?

swuehl
MVP
MVP

If you do need a record based comparision, try

=Count({$<NR_ANO = {"=NR_ANO=NR_ANO_INICIO_COMPETENCIA"} >} DISTINCT CODIGO) 

Not applicable
Author

Hi Swuehl,

I tried to use this expression like that you, but doesn´t work to.

I need count CODIGO when NR_ANO = NR_ANO_INICIO_COMPETENCIA

Thak you

swuehl
MVP
MVP

Have you tried my second expression? If you say, it doesn't work, do you get no results, zero or something, but obviously wrong? Any details on what you are getting back and what do you expect might help.

You could also try an expression without a set expression:

=count(distinct  if(NR_ANO = NR_ANO_INICIO_COMPETENCIA, CODIGO))

BTW, are you using QV10 or some older version?

Regards,

Stefan

Not applicable
Author

Hello!

This works fine, but for small amount of records...

Well, thank for your help, and if there is another ideia, please, send me.

Joao

swuehl
MVP
MVP

Well, I still think that

=Count({$<NR_ANO = {"=NR_ANO=NR_ANO_INICIO_COMPETENCIA"} >} DISTINCT CODIGO)

should work. It's hard to help you if you don't give some more information...

If it's about performance, a distinct count on large data volume is probably always performing not very well.

You could try some of the methods e.g. described in the manual to improve performance on distinct counts.

For example, you could create a new table

LOAD DISTINCT

CODIGO, 1 as CODIGO_DIST

resident TABLE_1;

then do a sum( .... CODIGO_DIST) instead of the count( distinct .... CODIGO)