Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
sebastian_fager
Contributor III
Contributor III

Sum Aggr()

Why dosen't this works? 😕

Sum(aggr( DISTINCT sum({<Attribute = {'M1'}>}ConsumptionPerDay*5) * RecipeShare, ProductID))

It dosen't sum if it's several ProductIDs. It works if there are only one ProductID.

I have also tried:

sum(aggr( sum($(vVariable)),ProductID))

Where $(vVariable) = sum({<Attribute = {'M1'}>}ConsumptionPerDay*5) * RecipeShare

1 Solution

Accepted Solutions
swuehl
MVP
MVP

I think I have a different correct result:

RawMaterialID Sum(Aggr( Only(RecipeShare) * Only(Forecast), RawMaterialID, ProductID))
4,1
280254,1

View solution in original post

5 Replies
sunny_talwar

What is the dimension where you are doing this? Can you may be share a sample to see what might not be working in this.

swuehl
MVP
MVP

I assume RecipeShare does not show a unique, single value per ProductID.

It's equivalent to write your expression as

Sum(aggr( DISTINCT sum({<Attribute = {'M1'}>}ConsumptionPerDay*5) * Only(RecipeShare), ProductID))

Use Aggregation Functions!

Not sure what you intend to calculate, but either apply an aggregation function other than Only() to RecipeShare, or maybe add RecipeShare to the Sum():

=Sum(aggr( DISTINCT sum({<Attribute = {'M1'}>} ConsumptionPerDay*5 * RecipeShare), ProductID))


Or maybe you need to add more dimensions to the aggr() function to allow Only(RecipeShare) to work.

sebastian_fager
Contributor III
Contributor III
Author

Hi,

I think i need one more dimension. The RecipeShare is a unique value per ProductID and raw material.

Example:

ProductID     RawMaterialID     RecipeShare     Forecast

5001             28025                    0,2                       10

5001             27051                    0,8                       10

4025              28025                    0,3                      7

4025              23047                    0,5                      7

4025              25045                    0,2                      7

And diffrent ProductID shares the same RawMaterialID. So if i choose raw material 28025 i want to see on a row how much RawMaterial  total i need based on the forecast for the ProductID.

Correct answer for 28025 would be 6,1 (0,2*10+0,3*7).

swuehl
MVP
MVP

I think I have a different correct result:

RawMaterialID Sum(Aggr( Only(RecipeShare) * Only(Forecast), RawMaterialID, ProductID))
4,1
280254,1
sebastian_fager
Contributor III
Contributor III
Author

Haha, you are correct!

Wonderful! It works great, big thanks!