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: 
Not applicable

Aggre function with sum and without sum

=SUM(aggr(SALES, SALESPERSON, PRODUCT))

=SUM(aggr(SUM(SALES), SALESPERSON, PRODUCT))

Can I ask what is the difference between the first function and second function. On one dataset, both functions give me the same result. On another dataset, both functions give me a different result. There is a difference but can someone explain to me in simple words? thanks

4 Replies
jonathandienst
Partner - Champion III
Partner - Champion III

Aggr() returns an n-dimensional matrix or hypercube (where n is the number of dimensions supplied) - evaluating the inner expression over each cell in the hypercube.

In the first case, SALES will be set to null if there is more than one possible value for any combination of SALESPERSON/PRODUCT. The inner expression is =SALES which QV treats as =Only(SALES).

The second expression will sum the values, so it returns a value for every cell.

I suspect that your first dataset has only one possible value of SALES for each combination of the dimensions and your second dataset has more than one possible value for one or more combinations of the dimensions.

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

Hi sir, thanks for your explanation. What about =aggr((SALES), SALESPERSON, PRODUCT) ?

Kushal_Chawda

see the difference

Capture.JPG

First expression will not be evaluated when there is two lines for combination of Salesperson and product, because as explained by Jonathan , your first expression is nothing but =SUM(aggr(only(Sales), SalesPerson, Product)). So when there is a two lines for combination of Salesperson and product it will return NULL, due to outer aggregation Sum(NULL) will become 0.

Where your second expression simply performing Sum(Sales) for each combination of Salesperson and product,because you are performing Sum in inner expression.

jonathandienst
Partner - Champion III
Partner - Champion III

>>What about aggr((SALES), SALESPERSON, PRODUCT) ?

This is the same as aggr(SALES, SALESPERSON, PRODUCT). Parentheses won't change anything.

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