简体   繁体   中英

Excel Pivot Table difference in columns of “shown as” values

Is there a way to let a pivot table calculate the difference between 2 columns automatically when the values are shown as a % of the parent column total?

Now I need to to manually but the table is dynamic and number of competitors may vary. Function seems so easy but can't find it after googling etc...

See example picture below of what I want to achieve.
(Column F automated by the pivot table is the goal)
数据透视表自动化的 F 列是目标

If trying to solve this with PivotTables, you've got a couple of options:

  1. Use a 'Traditional' PivotTable that's based on a range. This will give you percentage differences, but you can't get percentage point differences like you're asking for without using external formulas.
  2. Use a 'OLAP' PivotTable that's based on data you've added to the Excel Data Model. This will give you both percentage differences and percentage point differences, without having to resort to using external formulas.

In both cases, I recommend that you unpivot your data first, so that it is in what's known as a Flat File. Currently you're using a cross-tabulated data source (ie your source has columns called Year 1, Year 2), and the type of percentage comparisons across years you want to do doesn't work if your data is a crosstab. Basically, PivotTables aren't meant to consume cross-tabulated data.

Instead, you really want your data laid out so that you have a column called Amount and a column called Year, and then you can use the Show Values As options available from the right-click menu to show as percentage differences across years. To transform your data into a flat file, see my answers at convert cross table to list to make pivot table

That said, you can still use the GETPIVOTDATA function on your existing (unpivoted) data layout in a way that is somewhat more robust to changes in your PivotTable structure than just subtracting one reference from the other:

在此处输入图片说明

But again, I recommend transforming your data into a Flat File. Then you can additionally do the following:

Using a 'Traditional' PivotTable:

You can kinda solve your problem entirely within a self contained 'Traditional' PivotTable if you drag the Amount column to the Values area, put the Year column in the Columns area, put your Competitors in the Rows area, and choose one of the percentage Show Values As options you'll see when you right-click a cell in the Values area.

I say kinda , because without using external formulas (or without calculating the percentages back in your source data), you can only get it to show percent increases (see far right column), not percentage point increase like you want (see far left column). That said, I think percent increase is less confusing. But I guess it depends on what you want to show. If you want to show say change in market share from one year to the next, then percentage points make sense.

在此处输入图片说明 在此处输入图片说明

Of course, you could always use the GETPIVOTDATA function to do the additional math for you like we did earlier, like I've done on that left hand side.

Using an OLAP PivotTable based on the DataModel

Calculating percentage point increases likely requires using PivotTables built using the Data Model. See my answer at https://stackoverflow.com/a/49973465/2507160 that explains a little about the Data Model (although it doesn't answer this specific question).

Here's the result:

在此处输入图片说明 在此处输入图片说明

Here's the measures I used to do this:

Total Year 1: =CALCULATE(SUM(Table2[Value]),ALLSELECTED(Table2[Competitor]),Table2[Year] = "Year 1")

Total Year 2: =CALCULATE(SUM(Table2[Value]),ALLSELECTED(Table2[Competitor]),Table2[Year] = "Year 2")

% Year 1: =CALCULATE(SUM(Table2[Value]),Table2[Year] = "Year 1")/[Total Year 1]

% Year 2: =CALCULATE(SUM(Table2[Value]),Table2[Year] = "Year 2")/[Total Year 2]

pp Diff: = [% Year 2] -[% Year 1]

You can add Calculated Fields to Pivot Tables, of varying levels of complexity. Finding the difference between two fields is about as simple as it gets.

The example below is borrowed from contextures.com , where there are many more examples more further information.


To add a calculated field:

  1. Select a cell in the pivot table, and on the Excel Ribbon, under the PivotTable Tools tab, click the Options tab ( Analyze tab in Excel 2013).

  2. In the Calculations group, click Fields, Items, & Sets , and then click Calculated Field .

    功能区计算字段

  3. Type a name for the calculated field, for example, RepBonus .

  4. In the Formula box, type =Total * 3%

  5. Click Add to save the calculated field, and click Close .

    插入计算字段

  6. The RepBonus field appears in the Values area of the pivot table, and in the field list in the PivotTable Field List .

数据透视表中的计算字段

( Source )


EDIT:

@jeffreyweir - I'm not gonna lie, I don't know off the top of my head how to make this work (and don't have time to experiment) but by the looks of these options, isn't a calculated field with a "straight subtraction" of existing fields (ie., 3$-2%=1%) very possible with Difference from ? (as opposed to % Difference from which is also an option but for a different result).

In fact, automatic year-over-year difference reporting should be readily possible with the <previous> and <next> comparison operators...?

(Click to Embiggen)

图像1 图像2

Also, did you see the link where I got the example? Kind of a hoakey site but it has some more complex pivot table instructions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM