Skip to main content
Announcements
NEW: Seamless Public Data Sharing with Qlik's New Anonymous Access Capability: TELL ME MORE!
cancel
Showing results for 
Search instead for 
Did you mean: 
MPape
Contributor II
Contributor II

Totals in pivot table (aggr)

Having trouble with wrong totals in a pivot table, the pivot table columns are year-week or year-month, and rows are invoice data per product. Total should be 87,14 but we are getting 86,57.

I read in another topic that you should put your measure in a aggr function, apparantly it doesn't change the outcome of the measure but only fixes your totals in the pivot table? I just can't get it to work properly, getting 0 as results or just random results. 

Measure without aggr:

=Sum({<Type*={'Finance Logs', 'Invoice Rows'}, KamerbezetJN={"Ja"}, Datum={"<$(=today())"}>} KamerDagenTeller) /
Only({< Type*={'Finance Logs', 'Invoice Rows'}, KamerbezetJN={"Ja"}, Datum={"<$(=today())"} >}[Dagen per week])

One of my tries:

aggr(Sum({<Type*={'Finance Logs', 'Invoice Rows'}, KamerbezetJN={"Ja"}, Datum={"<$(=today())"}>} KamerDagenTeller) /
Only({< Type*={'Finance Logs', 'Invoice Rows'}, KamerbezetJN={"Ja"}, Datum={"<$(=today())"} >} [Dagen per week]), JaarWeek, [products.description])

If anyone has any ideas or tips, would be very much appreciated. 

Labels (2)
1 Solution

Accepted Solutions
MPape
Contributor II
Contributor II
Author

Was able to fix it after all, had to add the sum and not only order by products.description but also order by locations 

sum(aggr(Sum({<Type*={'Finance Logs', 'Invoice Rows'}, KamerbezetJN={"Ja"}, Datum={"<$(=today())"}>} KamerDagenTeller), JaarWeek, [locations.H_name3], [products.description]) /
aggr(Only({< Type*={'Finance Logs', 'Invoice Rows'}, KamerbezetJN={"Ja"},  Datum={"<$(=today())"} >} [Dagen per week]), JaarWeek, [locations.H_name3], [products.description]))

View solution in original post

3 Replies
Or
MVP
MVP

Not sure what your totals are supposed to represent, but you would need to aggregate the aggr(), e.g. sum(aggr(stuff)) or avg(aggr(stuff)) to tell Qlik how to handle the fact that multiple rows are returned.

MPape
Contributor II
Contributor II
Author

The totals are perfect with this version, the results (before they're totalled) are wrong though, so I assume my aggr() is still in a wrong position? 

SUM(aggr(Sum({<Type*={'Finance Logs', 'Invoice Rows'}, KamerbezetJN={"Ja"}, Datum={"<$(=today())"}>} KamerDagenTeller) /
Only({< Type*={'Finance Logs', 'Invoice Rows'}, KamerbezetJN={"Ja"}, Datum={"<$(=today())"} >} [Dagen per week]), JaarWeek, [products.description]))

MPape
Contributor II
Contributor II
Author

Was able to fix it after all, had to add the sum and not only order by products.description but also order by locations 

sum(aggr(Sum({<Type*={'Finance Logs', 'Invoice Rows'}, KamerbezetJN={"Ja"}, Datum={"<$(=today())"}>} KamerDagenTeller), JaarWeek, [locations.H_name3], [products.description]) /
aggr(Only({< Type*={'Finance Logs', 'Invoice Rows'}, KamerbezetJN={"Ja"},  Datum={"<$(=today())"} >} [Dagen per week]), JaarWeek, [locations.H_name3], [products.description]))