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

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
jorgie
Contributor III
Contributor III

Count Distinct Expression (set parameter)

Hi to all,

 

I want to count customers that had Sales>0 for a date range but only for the one with the older date.

For example

customer date Count( Distinct   if (Sales>0, [Customer])    ) new metric
totals   2 2
CUS_A 15/05/24 1 1
CUS_A 19/06/24 1 -
CUS_A 27/07/24 1 -
CUS_A 31/08/204 1 -
CUS_B 16/07/24 1 1
CUS_B 19/08/24 1 -
CUS_B 21/09/24 1 -

 

which can also be presented as

month Count( Distinct   if (Sales>0, [Customer])    ) new metric
totals 2 2
05 2 1
06 1 -
07 2 1
08 2 -
09 1 -

 

I tried to use set expression but not successfully

 

To sum up I try to count only the first time that a customer bought in the selected range of dates.

Not access to load editor and set vVariables

Thank you all for the time and help 

Labels (4)
1 Solution
7 Replies
hic
Former Employee
Former Employee

Try

Count({<Customer={"=Sum(Sales)>0"}>} distinct
   Aggr(
      If(Min(total <Customer> Date)=Date, Only(Customer)),
      Customer,
      Date)
   )

jorgie
Contributor III
Contributor III
Author

Thank you very much!!!!

I must admit, I spend all day in my notes and chatgtp having no results!!!

There is nothing like the community.

I will try to reverse code in order to understand it.

 

one more question, if it was to analyze it in ProductA and ProductB, where for product A value is 5 and for B also 5. but the total of distinct count is 7 (some customers exist in both products) is there a change i must make at code? 

the current just sums line.

 

thank once again

hic
Former Employee
Former Employee

If you use Product as dimension instead of Customer, you need to add this in the Aggr():

Count({<Customer={"=Sum(Sales)>0"}>} distinct
   Aggr(
      If(Min(total <Customer> Date)=Date, Only(Customer)),
      Customer,
      Product,

      Date)
   ) 

jorgie
Contributor III
Contributor III
Author

Thanks again!

Recently I had some seminars for qliksense.

Unfortunately didn't help me reach the depth of knowledge I need.

Any suggestion on where and how to learn more?

Is the any dictionary type to have a list of all function and a range of examples? Qliksense Documentation  in site didn't help much.

 

Thank you for your time and sharing your knowledge  

hic
Former Employee
Former Employee

There are a number of good videos on YouTube. Search for e.g. Mike Tarallo.
https://www.youtube.com/watch?v=YMQJnKMkfxg&t=50s

Or you can get a book:

Picture of book.png

jorgie
Contributor III
Contributor III
Author

sorry I was in haste and too enthusiastic ...

after checking my data set I realized that was making the calculation in all Date values.

I am trying to make the calculation based on the date range selection.

 

PS I need to study more about expressions.... 

 

thank once again