Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Connect 2026 Agenda Now Available: Explore Sessions
cancel
Showing results for 
Search instead for 
Did you mean: 
sudms
Contributor
Contributor

Find the distinct count using count if

Hello,

I am trying to get the total distinct count from below table.

CategorySubCatID
ACSACS10
ACSChat9
ACSEmail6
ACSEmail12
ACSEmail12
ACSEmail12
ACSEmail12
ACS 11
ChatChat1
ChatChat4
ChatEmail1
ChatEmail1
ChatOther5
Chat 2
ACSOther12

 

Here if you see I have two conditions like

1> SubCat should not be null

2> Category and SubCat should not match

With this I want the single value in my KPI of distinct count 5. I tried with below query but it gives 6 for the Aggr.

Sum(Aggr(IF(Len(SubCat)>0 and SubCat<>Category, count(distinct ID)),SubCat,Category))

 

Any solution to get the answer.  

Labels (2)
1 Solution

Accepted Solutions
Kushal_Chawda

@sudms  best way to do it is create a flag in script for the required conditions and use that flag in expression to get the count

Data:
LOAD Category,
            SubCat,
            if(len(trim(SubCat))>0 and SubCat<>Category,1,0) as Flag,
            ID
FROM Table;

Now, create a expression like below

=Count({<Flag={1}>}DISTINCT ID)

 

View solution in original post

1 Reply
Kushal_Chawda

@sudms  best way to do it is create a flag in script for the required conditions and use that flag in expression to get the count

Data:
LOAD Category,
            SubCat,
            if(len(trim(SubCat))>0 and SubCat<>Category,1,0) as Flag,
            ID
FROM Table;

Now, create a expression like below

=Count({<Flag={1}>}DISTINCT ID)

 

Community Browser