+ Reply to Thread
Results 1 to 13 of 13

Creating difference / variance columns in pivot

  1. #1
    Registered User
    Join Date
    05-20-2009
    Location
    Switzerland
    MS-Off Ver
    Excel 365
    Posts
    45

    Creating difference / variance columns in pivot

    I have a challenge for which I need some help

    1. I have an excel which lists all sales orders for a 2 year period

    2. I have created a pivot which shows for my top 40 customer (sorted by sales amount) the sales and margin in previous year and current year

    3. I would like to add 2 columns inside the pivot (on the right side) for the variance between this year and previous year for sales and margin (see excel attached)

    Can you please advise me how to achieve this and keep the layout as shown in the file?
    Attached Files Attached Files

  2. #2
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Creating difference / variance columns in pivot

    Hi,

    Is it OK to add a new column to your source data?
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  3. #3
    Registered User
    Join Date
    05-20-2009
    Location
    Switzerland
    MS-Off Ver
    Excel 365
    Posts
    45

    Re: Creating difference / variance columns in pivot

    What would you like to add?

  4. #4
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Creating difference / variance columns in pivot

    A column to calculate the year. You need a calculated item in the pivot table to calculate 2016-2015 but you can't add a calculated item while the date field is grouped.

  5. #5
    Registered User
    Join Date
    05-20-2009
    Location
    Switzerland
    MS-Off Ver
    Excel 365
    Posts
    45

    Re: Creating difference / variance columns in pivot

    That should not be a problem

    See attached
    Attached Files Attached Files

  6. #6
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Creating difference / variance columns in pivot

    Do you know how to create a calculated item?

  7. #7
    Valued Forum Contributor
    Join Date
    09-25-2015
    Location
    Nowy Tomysl, Poland
    MS-Off Ver
    2019, O365
    Posts
    398

    Re: Creating difference / variance columns in pivot

    Hello,
    See change your source data and formulas in the fields of computing
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    05-20-2009
    Location
    Switzerland
    MS-Off Ver
    Excel 365
    Posts
    45

    Re: Creating difference / variance columns in pivot

    I have done some simple ones

    How can you do a calculated item to calculate the difference between current year and previous year for the sales or margin?

  9. #9
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Creating difference / variance columns in pivot

    Once you've ungrouped your date field and removed it from the pivot, add the new year column to the pivot in its place. Then select one of the year cells in the pivot and add a calculated item (not calculated field) called variance using the formula ='2016'-'2015' and that will produce the result you want.

  10. #10
    Registered User
    Join Date
    05-20-2009
    Location
    Switzerland
    MS-Off Ver
    Excel 365
    Posts
    45

    Re: Creating difference / variance columns in pivot

    Ok, I think I got it but lets make this future proof

    What if we are in 2017 and I want to compare 2017 vs 2016 or if I want to compare 2015 vs 2014
    This Excel is linked against a database table where I filter on start and end date and when I refresh the data for a 2 year period is pulled of the database in what I call the datasheet and then the pivot will be updated on the data in the data sheet

    Not sure if this is clear but it is still early :-(

  11. #11
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Creating difference / variance columns in pivot

    I have just looked at your new file- the data layout seems to be completely different from the first one.

    With the original layout, if you will only have two years in the source data at any time you could define the calculated item using the formula =Year[2]-Year[1] and it will always subtract the earlier year from the later one.
    Last edited by xlnitwit; 10-28-2016 at 03:08 AM.

  12. #12
    Registered User
    Join Date
    05-20-2009
    Location
    Switzerland
    MS-Off Ver
    Excel 365
    Posts
    45

    Re: Creating difference / variance columns in pivot

    I am sorry to create extra confusion but I created a Version 2 of the file which I cleaned up and followed your instruction to created the calculated item
    The only thing that I did not manage to do is working with different years re your last reply
    Attached Files Attached Files

  13. #13
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Creating difference / variance columns in pivot

    Unfortunately, it is not possible to use the relative item references when one of your fields is set to autosort. You could add a new column that labels the data as Current year and previous year, and then use those in the item calculation, or use some code to update the calculation.

    I think those are the only real options in Excel 2007, other than perhaps adding the data fields again and choosing to display them as the Difference from the previous field. You would need to hide some columns to maintain the current layout.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 6
    Last Post: 04-09-2021, 01:59 AM
  2. VBA Code to find out the difference in variance
    By aravindkm in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-12-2013, 03:20 AM
  3. Replies: 1
    Last Post: 06-13-2012, 06:30 PM
  4. Pivot Table issue --variance columns
    By klopeks in forum Excel General
    Replies: 1
    Last Post: 10-05-2011, 12:35 PM
  5. Difference/variance problem
    By bmwgolfer in forum Excel General
    Replies: 1
    Last Post: 09-19-2007, 05:09 PM
  6. [SOLVED] Pivot Tables - Variance and Variance %
    By PJS in forum Excel General
    Replies: 2
    Last Post: 01-17-2006, 11:15 PM
  7. [SOLVED] Pivot Tables - Variance and % Variance fields
    By CraigS in forum Excel General
    Replies: 5
    Last Post: 01-05-2005, 09:06 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1