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

Announcements
Qlik GA: Multivariate Time Series in Qlik Predict: Get Details
cancel
Showing results for 
Search instead for 
Did you mean: 
rzaruvne
Contributor II
Contributor II

Count total distinct values over a combination of dimensions

The expression below counts the distinct values of dim guiaSolicitacaoInternacao, using TOTAL to disregard the chart dimensions.

Count(
TOTAL DISTINCT {
<
origemEventoAtencao = {'1','2','3'},
tipoInternacao = {'1','2','3','4','5'},
regimeInternacao = {'1','2'},
guiaSolicitacaoInternacao = {"*"},
dataRealizacao = {">=$(=Date(AddMonths(Max(dataCalendario), -12)))<=$(=Date(Max(dataCalendario)))"},
tipoRegistro = {'1','2'},
IsUltimaVersao = {'1'},
[Ultima incorporada] = {'1'}
>
} guiaSolicitacaoInternacao
)

I would like to take into account the combination of dimensions CNPJ, CNES, IBGE, that is, for each combination, count each guiaSolicitacaoInternacao once. There may be a case where there are two rows in my data with the same value for guiaSolicitacaoInternacao, but a different combination of CNPJ, CNES, IBGE, so the count would be 2 instead of 1

Labels (3)
1 Solution

Accepted Solutions
rubenmarin

Hi, if the dimensions are on the chart you can add them to TOTAL between < and >:

Count(
TOTAL <CNPJ, CNES, IBGE> DISTINCT {
<
origemEventoAtencao = {'1','2','3'},...

If not, or as an alternative, you can do an aggr to calculate each combination and sum all the combinations:

Sum(Aggr(Count(
TOTAL DISTINCT {
<
origemEventoAtencao = {'1','2','3'}...
} guiaSolicitacaoInternacao
),CNPJ, CNES, IBGE))

 

View solution in original post

3 Replies
rubenmarin

Hi, if the dimensions are on the chart you can add them to TOTAL between < and >:

Count(
TOTAL <CNPJ, CNES, IBGE> DISTINCT {
<
origemEventoAtencao = {'1','2','3'},...

If not, or as an alternative, you can do an aggr to calculate each combination and sum all the combinations:

Sum(Aggr(Count(
TOTAL DISTINCT {
<
origemEventoAtencao = {'1','2','3'}...
} guiaSolicitacaoInternacao
),CNPJ, CNES, IBGE))

 

rzaruvne
Contributor II
Contributor II
Author

Hi, thanks for your reply. It did work, but i had to remove the TOTAL from the expression.

rubenmarin

True, I missed that part.