Add new column to pivot table which calculates based on grand total

heretolearnexcel

New Member
Joined
Jan 22, 2019
Messages
26
Hi,

I have a table of data that I turned into a pivot table. Here is an example of more or less the data I'm working with:
DateType of movementProduct A In
Product A OutUnit CostUnit CostClientSelling PriceProduct A in Stock
10/11/19A203100
10/3/19B102Client A$2585
9/23/19C5290
9/22/19B95Client B$2091
9/15/19A30470
9/13/19B124Client D$1835
9/10/19A75100
9/02/19C83Client A$2512
8/24/19A10913

<tbody>
</tbody>


I turned the data into a pivot table and ended up with this:

Type of movementSum of Product A inSum of product A out
B10
A20
B9
B12
A30
A7
A10
Grand Total6731

<tbody>
</tbody>


I would like for the pivot table to display in the Grand Total row the difference between Sum of Product A in and Sum of Product A out, such that the result in the example would be =67-31= 36. I tried adding a formula next to the 31 which, supposing Type of movement= A1, would be in cell C9 and the 31 would be in D9. But if I filter for Type of movement and more values are added, changing the size of the pivot table, then the formula in D9 will no longer subtract the values from the grand total since they will no longer be in the original cells.
 

heretolearnexcel

New Member
Joined
Jan 22, 2019
Messages
26
add calculated field : ='Product A In' -'Product A Out'
Oh, it worked. I had already tried that but since in every row I only have a value either in 'Product A In' or 'Product A Out' the calculated result in each row was a negative number, and I thought I wasn't getting the calculation that I wanted; but I checked out the grand total and it is correct, only that it is a negative value. All I had to do was add an ABS to the formula: =ABS('Product A In' -'Product A Out') to make the value positive.

Thanks again Sandy.
 

heretolearnexcel

New Member
Joined
Jan 22, 2019
Messages
26
Oh, it worked. I had already tried that but since in every row I only have a value either in 'Product A In' or 'Product A Out' the calculated result in each row was a negative number, and I thought I wasn't getting the calculation that I wanted; but I checked out the grand total and it is correct, only that it is a negative value. All I had to do was add an ABS to the formula: =ABS('Product A In' -'Product A Out') to make the value positive.

Thanks again Sandy.
I just checked and an easier solution is to simply make the formula= 'Product A Out'- 'Product A In'. But I also just realized that the reason I need a different formula than the one you suggested is that my data is different; in my data the grand total for 'Product A Out' is larger than the one for 'Product A In'. More importantly the first represents sales and the latter returns, which is why I want to subtract them in that order. The formula you suggested works perfectly for the example I gave.
 
Last edited:

Forum statistics

Threads
1,078,364
Messages
5,339,760
Members
399,321
Latest member
ladeko

Some videos you may like

This Week's Hot Topics

Top