# Qlik Sense App Development

Not applicable

## 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?

1 Solution

Accepted Solutions
Not applicable

## Re: Count if / only qlik sense

And if you like the Only() idea maybe

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

11 Replies
Not applicable

## Re: Count if / only qlik sense

Maybe use

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

Not applicable

## Re: Count if / only qlik sense

or

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

Not applicable

## Re: Count if / only qlik sense

And if you like the Only() idea maybe

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

Not applicable

## Re: Count if / only qlik sense

Hi

this method worked the best

thanks again team !

Not applicable

## 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?

Not applicable

## 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

Not applicable

## 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.

Not applicable

## Re: Count if / only qlik sense

Thank you Stefan.

Not applicable

## Re: Count if / only qlik sense

This seems unexpected.

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