19 Replies Latest reply: May 21, 2017 7:38 AM by kushal chawda

# Distinct Count

Hi all

i write an expression for counting distinct customers who bought from us with two condition:

1)  at least they bought 1 product from us

2) our sales to them minus sales returns be greater than zero

so i write this:

sum(aggr(DISTINCT(if((sum(SalesQTY*Price)>0) and ((sum(SalesQTY*Price)-sum(SalesReturnsQTY*Price))>0,1,0)),Customer's ID))

i used Date (YY-MM) as dimension but it shows me "No data to display"!

is my formula right?

• ###### Re: Distinct Count

Can you please share application if possible that demonstrates the issue?

• ###### Re: Distinct Count

Qlikview 11

• ###### Re: Distinct Count

I didn't ask you provide the s/w version any more? I am asking about application whether how work around is going on and where we need to resolve the issue.

• ###### Re: Distinct Count

i used a bar chart to shows data

recently our It team change the Qlikview version to 12 on server but right now i'm using version 11

the odd thing is when i open my chart on the server it works perfectly but in my PC or any other device it does not work!!

before they upgrade to version 12, it was working great. is it possible that upgrading version cause this?

• ###### Re: Distinct Count

Try this first and look how this went?

If(Sum(SalesQTY*Price)>0 and (Sum(SalesQTY*Price)-Sum(SalesReturnsQTY*Price))>0, 1,0)

Then Try with out Summation

Aggr(If(Sum(SalesQTY*Price)>0 and (Sum(SalesQTY*Price)-Sum(SalesReturnsQTY*Price))>0, 1,0), [Customer's ID])

And then look and share snapshot for it

• ###### Re: Distinct Count

First one worked but the moment i used aggr function it shows me "No data to display"

• ###### Re: Distinct Count

Switch to Pivot whether you are in Straight?

• ###### Re: Distinct Count

May be clue in the brackets?

sum(aggr(DISTINCT(if((sum(SalesQTY*Price)>0) and ((sum(SalesQTY*Price)-sum(SalesReturnsQTY*Price))>0,1,0)),[Customer's ID]))

• ###### Re: Distinct Count

Hi Sergey

No, i tried, it does not work

• ###### Re: Distinct Count

So, try this condition:

sum(aggr(distinct sum(if(sum(aggr(SalesQTY*Price,Customer))>0 and (sum(aggr(SalesQTY*Price,Customer))-sum(aggr(SalesReturnsQTY*Price,Customer)))>0,1,0)), Customer))

• ###### Re: Distinct Count

Or make it simle:

Count(distinct {<Customer_bought={">0"}>}Customer)-Count(distinct {<Customer_returned={">0"}>}Customer)

• ###### Re: Distinct Count

in my expression there is an "And", i think you missed it in your formula

• ###### Re: Distinct Count

Sum(Aggr(If((Sum(SalesQTY*Price)>0) And ((Sum(SalesQTY*Price)-Sum(SalesReturnsQTY*Price))>0),1,0),[Customer's ID]))

• ###### Re: Distinct Count

No it does not work

• ###### Re: Distinct Count

Can you upload a sample file?

• ###### Re: Distinct Count

No i'm sorry ,all the data are in server i dont have access to them

• ###### Re: Distinct Count

Create a straight table and add Customer as dimension and add below expression. If you are getting correct result then the aggr should work.

If((Sum(SalesQTY*Price)>0) And ((Sum(SalesQTY*Price)-Sum(SalesReturnsQTY*Price))>0),1,0)

• ###### Re: Distinct Count

try this

=count( DISTINCT {<CustomerID ={"=sum(SalesQTY*Price)>0 and sum(SalesQTY*Price)-sum(SalesReturnsQTY*Price)>0"}>}CustomerID)