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

Sum function returning average (pivot table)

Hello,

I have the below function in a pivot table to calculate the ARS (average rate of sale) at higher levels.

However, when the ARS is subtotaled, the value is not the sum of all value. Instead, it recalculates in the subtotal line.

I know i can switch to a straight table and select the sum of rows option. Is there anyway to achieve the same result in a pivot table?

sum (ars * net sales) / sum (net sales)

Thanks,

Sara

1 Solution

Accepted Solutions
swuehl
MVP
MVP

Try this:

=sum(aggr(sum([Net Sales]*ARS) /sum( [Net Sales]),Vendor,Department,Group,Division))

edit:

=sum(aggr(sum([Net Sales]*ARS) /sum( [Net Sales]),Vendor))

should be enough, I think

edited by swuehl

View solution in original post

6 Replies
swuehl
MVP
MVP

Hi Sara,

I think it should be possible using advanced aggregation. There is an explanation and examples in the help file:

"Sum of rows in pivot tables"

Your expression could look like:

= sum(aggr(Sum(ars * [net sales]),YOURDIMENSION)) / sum(aggr(sum([net sales]), YOURDIMENSION))

Regards,

Stefan

edit: You probably don't need the sum(aggr(...)) for the second part, if the evaluation as total expression is fine here.

edited by swuehl

Not applicable
Author

That returned the same results. the total for vendors b,c,d,e should be 6.5648.

VendorNet SalesARS
a80.2694
Total80.269
b10.076
c160.473
d10.084
e415.9318
Total594.253

I've also tried this expression, which i got from another post...the only difference is that it returned 0 subtotals.

rangesum(above(sum(ars * net sales) / Sum(net sales),0, rowno(Total)))

VendorLW UnitsARS
a80.2694
Total80
b10.076
c160.473
d10.084
e415.9318
Total590
swuehl
MVP
MVP

How do you group your Vendors? Do you use another dimension not shown here?

Could you post your qvw file here or a sample that reproduces your problem?

Not applicable
Author

Vendors are grouped by department, departments by group, and groups by divisions.

swuehl
MVP
MVP

Try this:

=sum(aggr(sum([Net Sales]*ARS) /sum( [Net Sales]),Vendor,Department,Group,Division))

edit:

=sum(aggr(sum([Net Sales]*ARS) /sum( [Net Sales]),Vendor))

should be enough, I think

edited by swuehl

Not applicable
Author

Perfect, that worked. Thanks sooo much!!!