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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
mhassinger
Creator
Creator

Set Analysis with AND condition

I'm having a hard time structuring my set analysis to make this work. Let's say i have a simple table like:

CustomerProductQty
SmithWidget5
SmithCog10
JonesWidget5

I want to return a result of all customers who bought 2 or more widgets AND 4 or more cogs. Smith is the only customer that would meet that criteria.

My expression looks like this:

SUM({<Qty={">=2"},Product={'Widget'}> * <Qty={">=4"},Product={'Cog'}>} Qty)

The problem is that this returns zero results, because there are no records that meet both criteria (only one product per record). I've attached a sample QVW.

Any ideas?

1 Solution

Accepted Solutions
sunny_talwar

May be this:

{<Customer = p({<Qty = {'>=2'}, Product = {'Widget'}>}) * p({<Qty = {'>=4'}, Product = {'Cog'}>})>}

View solution in original post

4 Replies
varunreddy
Creator III
Creator III

Hi,

Try this:

aggr(SUM({<Qty={">=2"},Product={'Widget'}> * <Qty={">=4"},Product={'Cog'}>} Qty), Customer).

Let me know if you have any issues

Regards,

Varun

sunny_talwar

May be this:

{<Customer = p({<Qty = {'>=2'}, Product = {'Widget'}>}) * p({<Qty = {'>=4'}, Product = {'Cog'}>})>}

maxgro
MVP
MVP

sum( {$ <Customer={"=sum({$<Product={Widget}>}Qty)>=2"}*{"=sum({$<Product={Cog}>}Qty)>=4"}>} Qty)

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

I think you've got a couple of good answers there but I wanted to offer up a Set Analysis tip. Your answer was in your question: "return a result of all customers.." therefore your field selector is Customer.

-Rob