Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

conditional count of aggregated records

Hi,

In the enclosed app, I would like to modify the "<50 expression" formula so that instead of returning the total count of aggregated records for the current fields, it would show the count of records in the aggregation set for those whose "Quantity" expression  is less than 50. So for example, in the table we should get the following result for the expression:

w1, A , laptop = 0

w1, A, tv = 0

w1, C, bed = 2

w1,C, chair =2

w1, C, table = 2

w2, A, laptop = 1

w2, A, tv = 1

thanks.

1 Solution

Accepted Solutions
rubenmarin

Hi Dennis,

I used Sum(TOTAL <warehouse, category> Aggr(If(Sum(quantity)<50, 1), warehouse, category, product))

Check in attachment if this is what you want.

View solution in original post

16 Replies
jolivares
Specialist
Specialist

Let's see if I understand you require:  You need to count how many product is under 50 (in quantity) for each warehouse and category.  If it is right, try this expression:

Sum(Aggr(NODISTINCT Count(If(quantity<50,product)),warehouse,category))

jolivares
Specialist
Specialist

Try this one, too:

Sum(TOTAL <warehouse,category> Aggr(Count(If(quantity<50,product)),warehouse,category))

Not applicable
Author

Perfect. Thanks for your help.

Not applicable
Author

Actually  I need to use this expression in this syntax:

sum(Aggr(NODISTINCT Count(If(sum(quantity)<50,product)),warehouse,category))

Note that the if statement is testing against the sum(quantity). qlickview does not like this. I need to check against the sum of quantities of aggregated records for each warehouse, category, product aggregation. You will see that in the revised app with more data, your expression is returning the wrong results.

jolivares
Specialist
Specialist

In this case you need to group first the sum too...

Not applicable
Author

But the expression "Quantity" already has that value? I tried this syntax with no luck:

sum(Aggr(NODISTINCT Count(If([Quantity]<50,product)),warehouse,category))


Here, [Quantity] is the expression that calculates the sum(quality)

jolivares
Specialist
Specialist

Try this one...


Sum(TOTAL <warehouse,category> Aggr(Count(If(Aggr(Sum(Quantity),warehouse,category)<50,product)),warehouse,category))

jolivares
Specialist
Specialist

Try this one...


Sum(TOTAL <warehouse,category> Aggr(Count(If(Aggr(Sum(Quantity),warehouse,category,product)<50,product)),warehouse,category))

Not applicable
Author

None of them return the desired output. I have uploaded the app with your expressions in it. The desired output should be this:

w1 A laptop = 0

w1 A tv = 0

since this group two products both have sum(quantity) > 50.

w1 C bed = 2

w1 C chair = 2

w1 C table = 2

since this group has two members (chair and table) that have sum(quantity) < 50