Skip to main content
Announcements
Qlik Connect 2025: 3 days of full immersion in data, analytics, and AI. May 13-15 | Orlando, FL: Learn More
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Pivot table percentage error

I need to make this expression [Unit Cost] / [Balance] = [Unit Cost %] in pivot table but it give me a wrong records !

[Unit Cost]  >>>  sum(Debit-Credit)/Sum(TRXQTY)

[Balance]    >>>  sum(Debit-Credit)

[Unit Cost %]  >>>  (sum(Debit-Credit)/Sum(TRXQTY)) / (sum(Debit-Credit))


in the following picture i make the expression [Unit Cost]/434.464

that's why it's give me a true record, but when i change the date the record become wrong.

sorry for bad English

Untitled.png

Please check the attachment.

Regards,

2 Replies
jonathandienst
Partner - Champion III
Partner - Champion III

First, watch out for expressions like Sum(Debit - Credit) - this will return zero for all records where either Debit or Credit is null, even if the other value is not. Rather use

     Sum(RangeSum(Debit, -Credit))

     or

     Sum(Alt(Debit, 0) - Alt(Credit, 0))

     or

     Sum(Debit) - Sum(Credit)

Secondly, a pivot table uses the expression value method for the total, not sum of rows. When the expression is a ratio, the expression value will not be equal to sum of rows

"The ratio of the sums (expression value) is not the same as the sum of the ratios (sum of rows)"

You need Aggr() expressions to get sum of rows in a pivot:

Unit cost:

    =Sum(Aggr(Sum(RangeSum(Debit,  -Credit)) / Sum(TRXQTY), [Cost Sheet Grouping]))

[Unit Cost %]  >>> 

    =Sum(Aggr(Sum(RangeSum(Debit,  -Credit)) / Sum(TRXQTY) / Sum(RangeSum(Debit,  -Credit)), [Cost Sheet Grouping]))

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

Can you help me with any solution to view the percentage for each unit cost per balance like the picture. I mean, can I use other option except pivot table