14 Replies Latest reply: Mar 10, 2014 2:28 PM by Tomasz Zagdan

# Count total distinct problem

Hi

i'm trying to create a chart that shows to how many stores each product is sold.

X axis should show "Time" dimension (days / weeks / months) and Y axis should show two expressions:

- Total number of stores to which each product has been sold at least once in a period - for that I'm using function "count(distinct(StoreID))"  which works ok

- What % of the total store base that product was sold to. I was trying with the function below but it doesn't seem to work. Any suggestions?

count(distinct(StoreID))
/
count( total distinct (<Time> StoreID
))

Many thanks

• ###### Re: Count total distinct problem

if yes, use like below...

count(distinct(StoreID))
/
count( total distinct (<\$(=GetCurrentField(TIME)> StoreID
))

• ###### Re: Count total distinct problem

Yes its a cyclic group but doesn't seem to work..

• ###### Re: Count total distinct problem

count(distinct(StoreID))
/

count(distinct total<TIME> StoreID)

• ###### Re: Count total distinct problem

This one gives always 100% result

• ###### Re: Count total distinct problem

Have you tried below?

count(distinct(StoreID))
/
count(Distinct Total  (<\$(=GetCurrentField(TIME)> StoreID
))

• ###### Re: Count total distinct problem

yes, also no result it just doesn't show anything. Also fields after \$ sign are grey. Should they?

• ###### Re: Count total distinct problem

The correct syntax is:

count(distinct StoreID)
/
count(Distinct Total  <[\$(=GetCurrentField(TIME))]> StoreID
)

In order to troubleshoot your expression, turn your chart into a Straight Table (or a Pivot Table) and leave the expression Label empty. You will be able to see exactly how QlikView renders your expression formula.

Oleg Troyansky

Come and learn advanced QlikView techniques from the best:

• ###### Re: Count total distinct problem

Oleg,

the formula you provided indeed has no errors. However - still no results - no data is being displayed. Perhaps there is a different formula to get the same result?

thanks

Regards

CaptainP

• ###### Re: Count total distinct problem

Oleg,

I have another strange problem - perhaps its a bug that results in not showing the formula you provided.

On my bar chart I have a formula count(distinct(StoreID))

Surpirisingly each product that i click on has different bar colours - this didn't happen before in case of other charts with similar structure

Any ideas on that?

Regards

CaptainP

• ###### Re: Count total distinct problem

Dear, I think the answer given by OLEG is OK but if it is not working, you need to upload you sample data or qvw file.

This is the best way to get answer in quick fashion.

• ###### Re: Count total distinct problem

Try this

count(distinct(StoreID))
/
count(
total<Time> StoreID)

• ###### Re: Count total distinct problem

this one always gets result 100%. So no matter what product I click on I always have 100% which is not really the case

• ###### Re: Count total distinct problem

Captain,

I think we've been trying to solve different issues... In our responses, we tried to show you how to calculate the share of the TOTAL, i.e. disregard the dimension value in the denominator.

What you are trying to do is to calculate the percentage of the Store count by product, compared to all the stores in general. So, in addition to disregarding the Dimension values, you want to disregard the selection of the Product. The corresponding formula would be:

count(distinct StoreID)
/
count({<Product = >}  Distinct Total  <[\$(=GetCurrentField(TIME))]> StoreID
)

This Set Analysis condition will cause the expression to disregard any selections made in the field Product. If you need to disregard any other selections, add them into the list of Modifiers, separated by coma,

Site comment to you and Manish:

DISTINCT is not a function, but rather a qualifier within an aggregation function. Therefore, it doesn't require a set of parenthesis after it. So, instead of :

count(distinct(StoreID))

it's enough to write:

count(distinct StoreID)

The extra set of parenthesis doesn't break the formula but makes it more cluttered and less readable.

cheers,

Oleg Troyansky