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

Announcements
Discover how organizations are unlocking new revenue streams: Watch here
cancel
Showing results for 
Search instead for 
Did you mean: 
nigel987
Creator II
Creator II

Count only if ..

Hi,

please help, this seems so basic but I still can't figure out how to do it.

I have several customers with a CustomerID. The customers can by certain products, which have a ProductType (e.g. Car, House, Food, etc).

How can I count the customers, who have bought ONLY(!) a car, and no house, food, etc...?

The closest I get is this (but I also counts customers which bought a car and a house:

Count({$<ProductType={'Car'}>} Distinct CustomerID)

Thanks for your help!

1 Solution

Accepted Solutions
tresesco
MVP
MVP

Try:

=Count({$<CustomerID=p({<ProductType={'House'}>}) * p({<ProductType={'Car'}>})>*<CustomerID={"=Count( Distinct ProductType)=2"}>} Distinct CustomerID ,' - ')

View solution in original post

27 Replies
Anonymous
Not applicable

your syntax is ok...

=Count({$<ProductType={'Car'}>} Distinct CustomerID)


what error you are getting??

nigel987
Creator II
Creator II
Author

Hi, there is no error. But it counts all users which ordered a car. I want to count users which ONLY ordered a car, but no other product type, etc.

Not applicable

Hi nihal your syntax is correct,

what error your getting

Untitled.png

Anonymous
Not applicable

With this set {$<ProductType={'Car'}>}, you would be getting Car only

nigel987
Creator II
Creator II
Author

I've attached a sample file.

effinty2112
Master
Master

Hi Nihal,

This is a really good question. Try

=Concat(DISTINCT {$<[CustomerID] =E({<ProductType -= {'Car'}>})>}[CustomerID],', ')

This should give you a concatenated string of all the CustomerIDs who bought only a car. If a customer bought a ProductType of anything other than 'Car' these orders would be captured by the set modifier <ProductType -= {'Car'}> and a CustomerID is excluded if an instance of it occurs in this set.

Hope it works!

tresesco
MVP
MVP

Try:

=Count({$<ProductType={'Car'}, CustomerID={"=Count( Distinct ProductType)=1"}>} Distinct CustomerID)

nagarjuna_kotha
Partner - Specialist II
Partner - Specialist II

Hi Nihal,

Can you tell me your expected output?

Regards,

Nagarjuna

effinty2112
Master
Master

Hi Nihal,

                    In my reply I concatenated up the CustomerID, of course you can just count them rather than list them.

Cheers