Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
stig1984
Creator II
Creator II

Issue with expression with differing dimensions

I have an expression which calculates the percentage of class 2 and waste generated in an individual production run and presents this in a chart.

                                                                                                                                                                                       

RunProductCategoryVarietyClass 1 countClass 2 countWaste counttotal countClass 2 %Waste %
210969PEARTOPFRUITCONFERENCE257401125850.00%0.43%
210974PEARTOPFRUITCONFERENCE127680125128930.00%0.97%
210975PEARTOPFRUITCONFERENCE663608167170.00%1.21%
211019PEARTOPFRUITCONFERENCE7200720.00%0.00%
211029KIWISTONEFRUIT_90000090000.00%0.00%
211030PEARTOPFRUITCONFERENCE43920043920.00%0.00%
211038PLUMSTONEFRUITANGELENO19440375500203151.85%2.46%
211043PEPPER REDPEPPER_7500457950.00%5.66%
211051APPLETOPFRUITGRANNY SMITH6000138061382.25%0.00%
211053PEARTOPFRUITCONFERENCE8208025084580.00%2.96%
  TOTAL698405131012713650.72%1.42%

                                                                                                                                                                                                                                              

RunProductCategoryVarietyClass 1 countClass 2 countWaste counttotal countClass 2 %Waste %
210969PEARTOPFRUITCONFERENCE257401125850.00%0.43%
210974PEARTOPFRUITCONFERENCE127680125128930.00%0.97%
210975PEARTOPFRUITCONFERENCE663608167170.00%1.21%
211019PEARTOPFRUITCONFERENCE7200720.00%0.00%
211029KIWISTONEFRUIT_90000090000.00%0.00%
211030PEARTOPFRUITCONFERENCE43920043920.00%0.00%
211038PLUMSTONEFRUITANGELENO19440375500203151.85%2.46%
211043PEPPER REDPEPPER_7500457950.00%5.66%
211051APPLETOPFRUITGRANNY SMITH6000138061382.25%0.00%
211053PEARTOPFRUITCONFERENCE8208025084580.00%2.96%
698405131012713650.72%1.42%

Expression -

Sum(Aggr(Sum({<Prod_Class -={'Class 1'}>}FPInnerCount),ProductionRun,Product,Prod_Class))/Sum(TOTAL<Product>Aggr(Sum({<Prod_Class>}FPInnerCount),ProductionRun,Product,Prod_Class))

This expression works perfectly if I use the product as a dimension and calculates the percentage of class 2 and waste only against the runs for that category.

However if I use the category or variety as a dimension instead I get the percentage calculated against all runs regardless of category or variety (i.e.; uses class 2 figure for cucumber and divides by total count for every run suitable for filter).

I have changed the 'Product' in the above expression for 'Category' and 'Variety' but still received the same results.

Any ideas?

1 Solution

Accepted Solutions
sunny_talwar

Not sure how this behave for other category, but works for Cucumber:

Sum(Aggr(Sum({<Prod_Class -={'Class 1'}>}FPInnerCount),Category,ProductionRun,Prod_Class))/

Sum(DISTINCT Aggr(NODISTINCT Sum(TOTAL<Product>Aggr(Sum({<Prod_Class>}FPInnerCount),Category,ProductionRun,Prod_Class)), Category, Product))

View solution in original post

4 Replies
sunny_talwar

Would you be able to share a sample? with expected output?

stig1984
Creator II
Creator II
Author

Please see stripped out sample attached.

A good example for working with on category is Cucumber - this only has one product within it (Cucumber whole) which means that it should return the same result for the product and the category (without filters both should return 1.91% class 2 but category currently returns 0.05%)

sunny_talwar

Not sure how this behave for other category, but works for Cucumber:

Sum(Aggr(Sum({<Prod_Class -={'Class 1'}>}FPInnerCount),Category,ProductionRun,Prod_Class))/

Sum(DISTINCT Aggr(NODISTINCT Sum(TOTAL<Product>Aggr(Sum({<Prod_Class>}FPInnerCount),Category,ProductionRun,Prod_Class)), Category, Product))

jonathandienst
Partner - Champion III
Partner - Champion III

Simplifying your expression may help:

Sum(Aggr(

  Sum({<Prod_Class -={'Class 1'}>} FPInnerCount)

  /

  Sum({<Prod_Class -={'Class 1'}>} TOTAL <Product> FPInnerCount),

ProductionRun, Product, Prod_Class))

and assuming that works, then for category:

Sum(Aggr(

  Sum({<Prod_Class -={'Class 1'}>} FPInnerCount)

  /

  Sum({<Prod_Class -={'Class 1'}>} TOTAL <Category> FPInnerCount),

ProductionRun, Category, Prod_Class))

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