Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Totaling a column in a Pivot Table

I'm having a problem with summing a column in a pivot table. I use the following formula for the Actual Revenue column which works correctly for each line item:

If(StatusID='Firm',
sum((numJTDEstimatedSal) * 1.12) ,
sum(PostAmt * RevFlag)
)

When you look at the subtotals or totals, only the status IDs <> 'Firm' are summed up. Sample data is listed below. Can anyone please tell me how I would go about getting the whole 'Actual Revenue' column to sum up correctly?

Thank you!

StatusEstimated RevenueActual Revenue
Billable$57,235.27$57,233.27
Billable$30,504.26$29,105.26
Billable$10,524.00$10,524.00
Billable$60,101.40$0.00
Billable$1,396.00$0.00
Firm$51,272.00$57,424.64
Firm$24,000.00$26,880.00
Firm$39,000.00$43,680.00
Total$274,032.93$96,862.53
Total274,032.93

$96,862.53

1 Solution

Accepted Solutions
johnw
Champion III
Champion III

Pivot tables always evaluate the expression for the total instead of summing the rows. On the total line, the StatusID has TWO values, not one, so evaluates to null in your comparison, giving you the else value. So your total line is probably sum(PostAmt * RevFlag)?

To do a sum of rows in a pivot table, you use aggr(). The basic form is this:

sum(aggr(your expression, your dimensions))

So in your case, something like this if I'm understanding your pivot table:

sum(aggr(If(StatusID='Firm',
sum((numJTDEstimatedSal) * 1.12) ,
sum(PostAmt * RevFlag)
),StatusID))

I think you can find more information under "advanced aggregation" in the help text.

View solution in original post

2 Replies
johnw
Champion III
Champion III

Pivot tables always evaluate the expression for the total instead of summing the rows. On the total line, the StatusID has TWO values, not one, so evaluates to null in your comparison, giving you the else value. So your total line is probably sum(PostAmt * RevFlag)?

To do a sum of rows in a pivot table, you use aggr(). The basic form is this:

sum(aggr(your expression, your dimensions))

So in your case, something like this if I'm understanding your pivot table:

sum(aggr(If(StatusID='Firm',
sum((numJTDEstimatedSal) * 1.12) ,
sum(PostAmt * RevFlag)
),StatusID))

I think you can find more information under "advanced aggregation" in the help text.

Not applicable
Author

John,

Thanks so much for your response and for the explanation! The aggr() function is exactly what I needed and everything is working now.