Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
sharathkolluru1803
Contributor II
Contributor II

Finding Count of Field against another field distinct values(Ignoring duplicates)

Hi Experts,

I want your help in finding the distinct number(count) of IDs where table is having 2 coloumns ID and Order,
1)Order values considered for distinct ID if those are different.
2)If the ID and Order combination is single value needs to be ignored
3)If the ID and Order combination repeats then those needs to be ignored.

ID                  Order
ghi123         449
ghi123         393
lmn123       543
xyz123         999
xyz123         999
xyz123         999
pqr123        678
pqr123        445
pqr123        877
abc123       436
abc123       436

After applying above conditions ID count should be 2 (ghi123, pqr123) as the values are differed.

I tried with Chart expression "Sum(Aggr(Count(distinct Order)>1,ID))" like this but result are not correct.

Please do help me to solve this issue? Thanks a ton in advance.

Labels (4)
2 Solutions

Accepted Solutions
sunny_talwar

Try this

Count(DISTINCT {<ID = {"=Count(DISTINCT Order) > 1"}>} ID)

View solution in original post

sunny_talwar

Your expression is acting like an if statement within the Sum(Aggr())

Count(distinct Order) > 1 gives -1 when true and 0 when false per id.... and then you add them up.... The better way to code this is

Sum(Aggr(If(Count(DISTINCT Order) > 1, 1, 0), ID))

View solution in original post

10 Replies
ajaykakkar93
Specialist III
Specialist III

Hi,

Please check the following script & output

Output:

IDCount(Distinct key)
pqr1233
ghi1232
abc1231
lmn1231
xyz1231

 

Script : 

 

d:
load * Inline [
ID,Order
ghi123,449
ghi123,393
lmn123,543
xyz123,999
xyz123,999
xyz123,999
pqr123,678
pqr123,445
pqr123,877
abc123,436
abc123,436
];

final:
load 
ID&Order as key,
ID,
Order
Resident d;
drop table d;
exit script;

 

  

Please mark the correct replies as Solution. Regards, ARK
Profile| GitHub|YouTube|Extension|Mashup|Qlik API|Qlik NPrinting

sharathkolluru1803
Contributor II
Contributor II
Author

Thank you Ajay for quick reply.

But my Desired result is different, I need count of distinct key(ID)s where the values are not repeated  distinct only. Like key ‘pqr123’ has 3 different values so count of key(ID) is 1 and ‘ghi123’ has 2 different values so count of key is 1. So total count of distinct ID count is 2. Remaining all keys/ID values are either single or repeated with same values. So those needs to ignored in calculation.

ajaykakkar93
Specialist III
Specialist III

if(Count(Distinct key)>1,Count(Distinct key))

Please mark the correct replies as Solution. Regards, ARK
Profile| GitHub|YouTube|Extension|Mashup|Qlik API|Qlik NPrinting

ajaykakkar93
Specialist III
Specialist III

Then you will get 

pqr123 & ghi123

Please mark the correct replies as Solution. Regards, ARK
Profile| GitHub|YouTube|Extension|Mashup|Qlik API|Qlik NPrinting

sunny_talwar

Try this

Count(DISTINCT {<ID = {"=Count(DISTINCT Order) > 1"}>} ID)
sharathkolluru1803
Contributor II
Contributor II
Author

Thank You So much Sunny, You made my day.

sharathkolluru1803
Contributor II
Contributor II
Author

Hi Sunny

I have tried like this, "Sum(Aggr(Count(distinct Order)>1,ID))" but result is correct but coming in negative. Could you please help me in understanding of problem for the same.

sharathkolluru1803
Contributor II
Contributor II
Author

It is giving me total distinct count, but I need distinct count respective to ID. Thanks Ajay for your inputs.

ajaykakkar93
Specialist III
Specialist III

anytime, thank you

Please mark the correct replies as Solution. Regards, ARK
Profile| GitHub|YouTube|Extension|Mashup|Qlik API|Qlik NPrinting