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

Announcements
Want to see what's currently in public preview? We've pulled it all together in one place. Check it out here
cancel
Showing results for 
Search instead for 
Did you mean: 
kcville
Contributor II
Contributor II

Set Analysis - Group By in Where Clause

Hello

I am trying to write Set Analysis to do the following:

Count  distinct customers from sales transactions for a particular date range that have total sales <> 0

SQL would look something like this..

Select distinct customer from table where (select customer, Sum(sales) from table where payment date >=01/01/2018 and <=31/12/2018 Group by customer);

Thanks in Advance

 

 

3 Replies
jonathandienst
Partner - Champion III
Partner - Champion III

This may work:

Count({<customer = {"$(payment_date >= '01/01/2018' and payment_date <='31/12/2018'"}>} distinct customer)

Or this

Count({<customer = P({<payment_date ={>='01/01/2018' <='31/12/2018'}>})>} distinct customer)

 (depends on your actual data model)

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
Kashyap_R
Partner - Specialist
Partner - Specialist

Hi

try this 

Count(Distinct {<payment date={">=01/01/2009 and <=01/09/2009"}>}CustomerID) 

if this is showing 0 values and Counting them then try this

Count(Distinct {<payment date={">=01/01/2009 and <=01/09/2009"},0={">$(=Aggr(Sum(sales),CustomerID))"}>}CustomerID)

Hope this helps

Thanks

Thanks and Regards
Kashyap.R
kcville
Contributor II
Contributor II
Author

Thank you for your replies, however these are not working.

I really need to select the date cohort first and then check for aggregate sum greater than 0.

something like this..

 

If(payment_date >='01/01/2018' and <'31/12/2019', Count({$<customer={"=aggr(Sum(payment),customer) > 0"}>}distinct customer)

Thank you