Skip to main content
Announcements
Qlik Introduces a New Era of Visualization! READ ALL ABOUT IT
cancel
Showing results for 
Search instead for 
Did you mean: 
Subhasmita
Partner - Contributor
Partner - Contributor

Selection and Without Selection, different count

Hi Experts!

I am facing a peculiar issue in my Qlik Sense app. Due to security concern, can't attach sample file, however will try to explain as much as possible.

I am trying to find out distinct count of customer id at contract level for sales having non zero values. I am using below expression. 

Count(distinct
{<[Customer ID]={"=Sum(Total<[Contract ID], [Customer ID]> [Net Sales])>0"}>}
total <[Contract ID]> [Customer ID])

however this expression works well when contract ID is selected but when there is no contract id selection, count shows more which is not correct.

I have table similar to this.

Contract Cust ID sales
123 111 0
123 222 60
123 333 100
234 444 20
234 555 80

 

any leads will surely of great help, thanks!

Labels (1)
6 Replies
edwin
Master II
Master II

try 

edwin_0-1657207589562.png

i added a third contract to test sum=0:

edwin_1-1657207627068.png

 

Subhasmita
Partner - Contributor
Partner - Contributor
Author

Thanks for checking on this Edwin!

I would need the count of customers for the contract which has positive sales. so the example you shared should give me ideally as below.

 

Contract Cust ID Prod sales Count of Cust
123 333 100 2
123 222 60 2
123 111 0 2
234 555 80 2
234 444 20 2
456 500 50 1
456 200 -25 1
456 201 -25 1

 

 

this expression is giving me correct count when contract is selected but not when contract is not selected and we see contracts on the table.

 

Count(distinct
{<[Customer ID]={"=Sum(Total<[Contract ID], [Customer ID]> [Net Sales])>0"}>}
total <[Contract ID]> [Customer ID])

edwin
Master II
Master II

so your criteria is the slaes PER contract AND customer >0 and not sales per contract.  is that rt?

edwin
Master II
Master II

the general solution is the same.  using set analysis to find the sum that is > 0.  however, this requires a single field so you need to fabricate that field:

edwin_0-1657305817486.png

 

note that i tweaked the data a little as well to test the last contract.  cust id 200 will result in 0 total so that should not be included:

edwin_1-1657305889953.png

cust 111 is also not included

Subhasmita
Partner - Contributor
Partner - Contributor
Author

thanks for the solution Edwin! it seems to work with the example data set.

Unfortunately, i have contract and cust ID coming from different tables, not sure how can i combine them.

 

thanks for looking the problem!

edwin
Master II
Master II

you dont need to combine tables.  it looks like you dont have a proper DM yet which is a different problem from what youve posted.  leave them separate and make sure you have a single common key between them.  a contract must be with only one customer so cust ID would be your key