Results 1 to 6 of 6

Thread: Add new column to pivot table which calculates based on grand total
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    New Member
    Join Date
    Jan 2019
    Posts
    23
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

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

    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:
    Date Type of movement Product A In
    Product A Out Unit Cost Unit Cost Client Selling Price Product A in Stock
    10/11/19 A 20 3 100
    10/3/19 B 10 2 Client A $25 85
    9/23/19 C 5 2 90
    9/22/19 B 9 5 Client B $20 91
    9/15/19 A 30 4 70
    9/13/19 B 12 4 Client D $18 35
    9/10/19 A 7 5 100
    9/02/19 C 8 3 Client A $25 12
    8/24/19 A 10 9 13


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

    Type of movement Sum of Product A in Sum of product A out
    B 10
    A 20
    B 9
    B 12
    A 30
    A 7
    A 10
    Grand Total 67 31


    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.

  2. #2
    New Member
    Join Date
    Jan 2019
    Posts
    23
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

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

    Any ideas anyone?

  3. #3
    Board Regular sandy666's Avatar
    Join Date
    Oct 2015
    Posts
    3,010
    Post Thanks / Like
    Mentioned
    33 Post(s)
    Tagged
    1 Thread(s)

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

    add calculated field : ='Product A In' -'Product A Out'
    I know you know but I forgot my Crystal Ball and don't know what you know



    In the first post, show the type of machine (PC / Mac) and the Office version you are working on
    I don't use vba in any form!

  4. #4
    New Member
    Join Date
    Jan 2019
    Posts
    23
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

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

    Quote Originally Posted by sandy666 View Post
    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.

  5. #5
    Board Regular sandy666's Avatar
    Join Date
    Oct 2015
    Posts
    3,010
    Post Thanks / Like
    Mentioned
    33 Post(s)
    Tagged
    1 Thread(s)

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

    but positive result isn't truth
    I know you know but I forgot my Crystal Ball and don't know what you know



    In the first post, show the type of machine (PC / Mac) and the Office version you are working on
    I don't use vba in any form!

  6. #6
    New Member
    Join Date
    Jan 2019
    Posts
    23
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

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

    Quote Originally Posted by heretolearnexcel View Post
    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 by heretolearnexcel; Oct 12th, 2019 at 05:47 PM.

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •