# New to Qlik Sense

Discussion board where members can get started with Qlik Sense.

New Contributor II

## Count if with multiple conditions

Hello everyone,

I want to make a KPI that counts distinct customers for the nested if conditions below.

I figured this out but it gets '-' .

count(if(orderstatus={'0'} or orderstatus={'1'} or orderstatus={'2'} and len(string)='12' ,
if(sum(aggr(count(distinct(orderdate)), [customer]))>='2' and aggr(max(orderdate),[customer])>=Addmonths(Today(),-12) and aggr(max(orderdate),[customer])<=(Today())) distinct [customer])

Looking forward to the correct syntax.

Thanks.

9 Replies
Partner

## Re: Count if with multiple conditions

Hi,

try in this way:

Count(distinct if(
Match(orderstatus,'0','1','2')>0 and Len(string)=12 and Aggr(count(distinct orderdate), [customer])>=2
and aggr(max(orderdate),[customer])<=(Today()), [customer]))

MVP

## Re: Count if with multiple conditions

Try this

``````Count(DISTINCT {<
[orderstatus] = {'0', '1', '2'},
[string] = {"=Len(string) = 12"},
[customer] = {"=Count(DISTINCT orderdate) >= 2 and Max(orderdate) >= AddMonths(Today(), -12) and Max(orderdate) <= Today()"}
>} [customer])``````
New Contributor II

## Re: Count if with multiple conditions

Works perfectly Sunny, but I forgot this one ;

I need this condition for each customer as well :

interval(max(orderdate)-date(max(orderdate,2)),'m')<='24'

Is it safe to add it under [customer] conditions, or do i need to do

interval(aggr(max(orderdate),[customer])-aggr(date(max(orderdate,2)),'m'), [customer])<='24'   ?

MVP

## Re: Count if with multiple conditions

I think within the list of condition on customer is where it should be added

``````Count(DISTINCT {<
[orderstatus] = {'0', '1', '2'},
[string] = {"=Len(string) = 12"},
[customer] = {"=Count(DISTINCT orderdate) >= 2 and Max(orderdate) >= AddMonths(Today(), -12) and Max(orderdate) <= Today() and (Max(orderdate)-Max(orderdate, 2)) <= 24"}
>} [customer])``````
New Contributor II

## Re: Count if with multiple conditions

Hi Sunny and thank you.

I just changed it to :

interval( (date(max(orderdate),'DD/MM/YYYY')- date(max(orderdate,2),'DD/MM/YYYY')),'m') <= '24'

because i wanted the difference in months.

MVP

## Re: Count if with multiple conditions

I don't think this is giving you the difference in month, is it?

``Interval((Date(Max(orderdate),'DD/MM/YYYY')- Date(max(orderdate,2),'DD/MM/YYYY')),'m')``

I think this would be in minutes

New Contributor II

## Re: Count if with multiple conditions

Okay so the default date difference is in months?

And i have another question which i am positive you can solve 🙂

Let's say i have

count{

[field1]={'such'],

[field2]={'such'},

[field3={("=count(field4)={0}, field4={ set analysis1}) AND "=count(field4)={1}, field4={ set analysis2}) }

distinct [field]}

Is something like that possible?

MVP

## Re: Count if with multiple conditions

I am not really sure I understand this... can you elaborate on this new requirement please

New Contributor II

## Re: Count if with multiple conditions

Okay let me see if I can rephrase my other question.

[customer]

as above and i had count(distinct(orderdates)=0 which needed to happen in the last year ( I figured it should be in the last 12 months with addmonths but definitely a date before today)

and a count(distinct(orderdates)>=1 which needed to happen in the last  2 years,

could i do for this field:

count{

[field1]={'such'],

[field2]={'such'},