11 Replies Latest reply: Oct 2, 2017 5:33 AM by Joanna Seldon

# Count if / only qlik sense

Hi

trying both ways , but wrong ..can I have some help please

I want to only ever count customers that only order on a specific month, and not on any other month of the year

e.g August

I have tried this way but don't work

Count(DISTINCT if([Month]='Aug', CustomerID))

I have heard you can do this with an only command

only({<[Month]={'Aug'}>} CustomerID)

but how do you count using an only?

• ###### Re: Count if / only qlik sense

Maybe use

Count({<CustomerID = e({<Month = e({<Month = {'Aug'}>}) >})>} DISTINCT CustomerID)

• ###### Re: Count if / only qlik sense

or

Count({<CustomerID = e({1<Month -= {'Aug'}>}) >} DISTINCT CustomerID)

• ###### Re: Count if / only qlik sense

And if you like the Only() idea maybe

Count({<CustomerID = {"=Only(Month)= 'Aug' "} >} DISTINCT CustomerID)

• ###### Re: Count if / only qlik sense

Hi

this method worked the best

thanks again team !

• ###### Re: Count if / only qlik sense

Hi

stefan

Count({<CustomerID = {"=Only(Month)= 'Aug' "} >} DISTINCT CustomerID)

I am trying to add stop a user selecting the dimension Department

i have tried adding the following

Count({< Department =,  CustomerID = {"=Only(Month)= 'Aug' "} >} DISTINCT CustomerID)

but the measure is still being affected

• ###### Re: Count if / only qlik sense

This seems unexpected.

Can you describe what happens when you select a specific department?

• ###### Re: Count if / only qlik sense

The expression search will be affected by the selection state, so maybe

Count({<Department=, CustomerID = {"=Only({<Department=>} Month)= 'Aug' "} >} DISTINCT CustomerID)

• ###### Re: Count if / only qlik sense

Hi

you cracked it

thank you Stefan / Team

Kind Regards

• ###### Re: Count if / only qlik sense

Stefan,

This is interesting - I'm trying to learn more about the E() and P() functions. Can you explain what you are trying to do here? My novice take on it is - moving from the innermost E outwards - that you are excluding all sales from the set that occurred in august, and then you are excluding all the remaining months. Seems like this would leave you with an empty set.

What am I missing?

• ###### Re: Count if / only qlik sense

Looking at the first expression:

1) Make a virtual selection of 'Aug' in Month field

2) Select excluded on virtual list box Month

Now this should result in all possible Month values except Aug being selected

3) Select excluded on virtual CustomerID list box

This should result on selection of CustomerID that don't have a relation to the Month selected (all Month except Aug).

Hm, maybe this selects also the Customer ID that don't have a relation to any Month (including Aug).

And using especially e() could get troublesome if other selections needs to be taken into account.

So Joanna is probably right that the third expression is the easiest expression to understand and maintain.

• ###### Re: Count if / only qlik sense

Thank you Stefan.