+ Reply to Thread
Results 1 to 25 of 25

Pivot Table - Calculated Field

  1. #1
    Registered User
    Join Date
    11-14-2014
    Location
    England
    MS-Off Ver
    2010
    Posts
    18

    Pivot Table - Calculated Field

    I need to add the following formula in a calculated field into a pivot to provide me with some rate and mix calculations.

    =(sales x (Margin% - Total Margin%))-(Sales / Total sales) and so on...

    Total above is the grand total for the column. All the above items are on my pivot via a local source data. However I can't figure out how to divide a cell by the grand total for for that column.

    I am using Office 2010 64 bit on Windows 7. Any guidance would be greatly appreciated.

    Regards

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,247

    Re: Pivot Table - Calculated Field

    If I understood you correctly, you can't do that without PowerPivot.
    Remember what the dormouse said
    Feed your head

  3. #3
    Registered User
    Join Date
    11-14-2014
    Location
    England
    MS-Off Ver
    2010
    Posts
    18

    Re: Pivot Table - Calculated Field

    Hi

    Thank you for the response. I have now switched to Power Pivot however I am not familiar with the dax formula which will do this for me.

    Say row 3, 4 & 5 have values in them (in the pivot) and row 6 has a grand total. What formula would I use to divide row 3 by row 6?

    Much appreciated.

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,247

    Re: Pivot Table - Calculated Field

    You'll want a measure that looks something like:
    =SUM(TableName[Sales])/CALCULATE(SUM(TableName[Sales]),ALL(TableName))

    The ALL(TableName) removes the filter context from the measure so that you get the grand total of all sales.

  5. #5
    Registered User
    Join Date
    11-14-2014
    Location
    England
    MS-Off Ver
    2010
    Posts
    18

    Re: Pivot Table - Calculated Field

    Thank you for your response. Much appreciated however I have another question pls.

    On the pivot, I have set up a new measure called GP Margin =(iferror(sum([TMTY FM£])/sum([TMTY Sales]),0)

    What would my formula be if I wanted to do the same here i.e. divide a cell by the grand total? I keep getting the following error (The 'SUM' function only accepts a column reference as an argument.)

    Any suggestions please?

  6. #6
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,247

    Re: Pivot Table - Calculated Field

    You need to use CALCULATE again:
    CALCULATE(SUM(TableName[FieldName]),ALL(TableName))
    will return the grand total for whichever field you specify.

  7. #7
    Registered User
    Join Date
    11-14-2014
    Location
    England
    MS-Off Ver
    2010
    Posts
    18

    Re: Pivot Table - Calculated Field

    Hi Romperstomper

    Just tried this formula =SUM(Table1[TMTY FM%])/CALCULATE(SUM(Table1[TMTY FM%]),ALL(Table1)) and it results in the following error - The 'SUM' function only accepts a column reference as an argument.

    FM% here doesn't come from the table, it is calculated as a measure from other data in the table. Could this be causing the issue?

  8. #8
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,247

    Re: Pivot Table - Calculated Field

    What's the formula for the measure? You may be able to simply use:

    =[TMTY FM%]/CALCULATE([TMTY FM%],ALL(Table1))

  9. #9
    Registered User
    Join Date
    11-14-2014
    Location
    England
    MS-Off Ver
    2010
    Posts
    18

    Re: Pivot Table - Calculated Field

    Formula for the measure is =iferror(sum([TMTY FM£])/sum([TMTY Sales]),0)

    TMTY - This month this year
    TMLY - This month last year

  10. #10
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,247

    Re: Pivot Table - Calculated Field

    What are you actually attempting to calculate?

  11. #11
    Registered User
    Join Date
    11-14-2014
    Location
    England
    MS-Off Ver
    2010
    Posts
    18

    Re: Pivot Table - Calculated Field

    Rate and Mix calculations - quiet a complex formula and the idea is that if anyone selects any report filter on the pivot, it works out the rate and mix calculations accordingly - at the moment I have to copy and paste the formula and ensure it is working every time as the number of rows are dynamic and change everytime the report filters change.

  12. #12
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,247

    Re: Pivot Table - Calculated Field

    I meant specifically. You want to show a percentage measure as a percentage of a grand total percentage?

  13. #13
    Registered User
    Join Date
    11-14-2014
    Location
    England
    MS-Off Ver
    2010
    Posts
    18

    Re: Pivot Table - Calculated Field

    It is as a percentage in the end - but I think the formula above is now working. Basically the formula is nested as it multiplies 6 items and then subtracts 2 to give the final result - I have managed to nest 2 items in the measure and it's working so far...Will try and finish the remainder and see what happens.

  14. #14
    Registered User
    Join Date
    11-14-2014
    Location
    England
    MS-Off Ver
    2010
    Posts
    18

    Re: Pivot Table - Calculated Field

    Hi Romperstomper

    Thank you for your help. I have managed to get everything working however one final question pls...

    Formula I need help with is this ->>> =calculate([Sum of TMTY Sales],all(Table1))
    Here the:
    Sum of TMTY Sales - Is the name of the pivoted field
    TMTY Sales - Is the name of the column in Table 1

    In my raw data I have data for multiple months (lets say TMTY total is £1m in the raw data tab). If I do not use any filters in excel this formula gives me the right result i.e. £1m in the above example.

    However when I filter on months or region etc, the value on the pivot table changes (let's say it is now £200k) however the result of this formula still brings back £1m in total.

    Is there a way this formula can only bring back the totals based on the items I have sliced / filtered on the pivot table rather than the total from the raw data in the PowerPoint data window (i.e. £200k instead of £1m)? BTW I am using Excel 2010 32 bit.

    Thanks in advance.

  15. #15
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,247

    Re: Pivot Table - Calculated Field

    If you simply want the sum of that field for the current filter context, you don't need calculate at all, just:
    =SUM(Table1[TMTY Sales])

  16. #16
    Registered User
    Join Date
    11-14-2014
    Location
    England
    MS-Off Ver
    2010
    Posts
    18

    Re: Pivot Table - Calculated Field

    Hi RomperStomper

    Below is a snapshot of the table

    Untitled.png

    I want the formula to divide E4 by E15, then E5 by E15 and so on. And I want it to work when different pivot slicers or report filters are selected as the all option takes all items in the raw data and doesn't consider what filter items have been selected.

    Thanks for your help .

  17. #17
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,247

    Re: Pivot Table - Calculated Field

    I wouldn't bother with a new measure at all for that. Just add the same measure to the table again, right click it and choose to show as % of column total.

  18. #18
    Registered User
    Join Date
    11-14-2014
    Location
    England
    MS-Off Ver
    2010
    Posts
    18

    Re: Pivot Table - Calculated Field

    I need it as a measure as the formula on the screenshot is just the first bit. The complete formula is below and the "as % of column total" will not work...

    Untitled 1.png

  19. #19
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,247

    Re: Pivot Table - Calculated Field

    What are the row fields? You'd have to make the filter context exclude those specifically.

  20. #20
    Registered User
    Join Date
    11-14-2014
    Location
    England
    MS-Off Ver
    2010
    Posts
    18

    Re: Pivot Table - Calculated Field

    When I use "=SUM(Table1[TMTY Sales])" the result is the same as cell E4 i.e. £4,084 yet I want it to show £1,774,802 (cell E15) as shown below

    Untitled 3.png

    Think about it this way - £4,084 / £4,084 = 1.0 yet the correct formula needs to be £4,084 / £1,774,802 = 0.0021

    Does this make it clearer?

  21. #21
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,247

    Re: Pivot Table - Calculated Field

    I understand what you want - I need to know what the row fields in your pivot are - i.e. the ones that distinguish row 4 from row 5 etc. The filter would have to specifically remove only those filters as the context for the measure so that any other filters you have in place are respected.

  22. #22
    Registered User
    Join Date
    11-14-2014
    Location
    England
    MS-Off Ver
    2010
    Posts
    18

    Re: Pivot Table - Calculated Field

    Hi

    Complete snapshot below.

    Untitled 6.png

  23. #23
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,247

    Re: Pivot Table - Calculated Field

    You need:

    =CALCULATE(SUM(Table1[TMTY Sales]),ALL(Table1[rowfieldname]))

    where rowfieldname is the name of the field with A, B, C etc in it.

  24. #24
    Registered User
    Join Date
    11-14-2014
    Location
    England
    MS-Off Ver
    2010
    Posts
    18

    Re: Pivot Table - Calculated Field

    Thanks a lot. All done and working

    Great support. A++++

  25. #25
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,247

    Re: Pivot Table - Calculated Field

    Glad to help. Please remember to mark the thread solved with the Thread Tools link at the top.

+ 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. [SOLVED] Referring to a Sub-Field on Calculated Field Pivot Table Column?
    By figo12 in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 01-27-2014, 02:02 PM
  2. Calculated pivot table field using pivot table data in calculation
    By BrittleStar in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 12-10-2012, 05:35 PM
  3. Replies: 0
    Last Post: 06-26-2012, 09:06 PM
  4. Replies: 1
    Last Post: 04-12-2010, 01:01 PM
  5. [SOLVED] pivot table formulas for calculated field or calculated item
    By Vicky in forum Excel General
    Replies: 3
    Last Post: 06-06-2006, 12:10 AM

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