Make a Pivot from Another Pivot Table in Excel

Share

Facebook
Twitter
LinkedIn

Recently, a client shared data with me that is clearly a pivot table and wanted me to make another pivot from it using Excel. This is a common and annoying problem we all face when working with Excel. Today, let me share my approaches for creating a pivot from another pivot report using Excel.

pivot from another pivot table in Excel - howto

Option 1: If you have access to “original” data

Ha, I know, but we can dream eh? So, if you do have access to the original data from which the pivot is generated, just use that data and make the new pivot as you want.

If you need help creating a pivot report in the first place, learn the process here.


Option 2: Making a Pivot from Another Pivot when you don’t have access to original data

Tbh, this is the real scenario for most of us. We have a pivot and don’t have access to the data that was used to make it. Now we need to make another pivot. In this case, follow the below steps.

Pivot from Another Pivot – FREE Excel Template

free excel template - pivot from pivot

I created a free Excel template to guide you thru the process with sample data. Download it here and use the sample data to understand the process better.

Step 1: Select and name your pivot range

  1. Select the entire pivot table (including any headers) in Excel.
  2. Go to the name box (next to formula bar on the left)
  3. Type the name “pivot_range”
  4. Pro tip: If you have multiple pivots, you can use names like “pivot_range1”, “pivot_range2”

See this illustration for the step.

creating a named range for pivot data

Step 2: Go to Data Ribbon and load up the “pivot” to Power Query

  1. Keep the pivot table selected
  2. Go to Data Ribbon
  3. Click on “From Table/Range” option in the Get & Transform Data area

This will load the Power Query Editor with your Pivot Table Data.

loading "pivot_range" to Power Query

Step 3: Let’s “unpivot” the Pivot Table with Power Query

Now that our “pivot table” is in Power Query, we can “unpivot” it and create a regular table. This can be used to make our new pivot table.

Here is a snapshot of how the Power Query editor looks with the pivot_range data.

Power Query editor with pivot data

[optional step] Promote headers if needed

Depending on how your source Pivot is setup, you may need to adjust the column headings in Power Query. For example, in my case, I need to promote the headers. To do this, click on “Use First Row as Headers” button in the Home ribbon of Power Query editor.

See below illustration.

fixing the headers with "use first row as header" option

Step 4: Replace “null” with value from above

In my sample pivot, you can see that Rep name is not printed in all rows, just the first row. This shows up as null in the Power Query editor for rest of the rows. We just need to fill these down based on the top value.

  • Select the column(s) with this problem
  • Go to “Transform” ribbon in Power Query Editor
  • Click on “Fill” and select Down to fill down all the nulls with the value from above
Filling nulls with value from above - Before vs. After

Step 5: Remove rows with “totals” & “sub-totals”

We don’t need totals or sub-totals any more. We will calculate them in the new pivot as needed. For now, let’s remove all the rows and columns that have totals.

  1. Select the first column that has “total” labels
  2. Click on “filter” button
  3. Uncheck any total labels.
  4. Repeat the steps for any other rows that need this clean-up step.
  5. Pro tip: Use Text Filters > Does not contain to filter out all rows with “total” word in them.
removing total and sub-total rows.

Step 6: Remove Grand total / Sub-total columns (if any)

Let’s also remove any “grand total” columns and “sub-total” columns from our pivot report. Right click on the column with totals and select “remove” to take this column out.

removing any grand total and sub-total columns

Step 7: Unpivot the data

Finally, our pivot report is ready to be unpivoted.

  1. Select the column(s) with row labels. In the above example, I selected “representative” and “day of week” columns
  2. Pro Tip: Hold SHIFT or CTRL to select multiple columns in one go.
  3. Right click on the column headings of either column.
  4. Select “unpivot other columns”
  5. This should reshape the pivoted data to unpivoted format.
  6. See this quick demo (GIF):
unpivoting / depivoting the data- quick demo

Step 8: Rename the new “attribute” & “value” columns

Double click on the newly added “attribute” and “value column headers to rename them to appropriate labels. In my case, I named them – Gender & Calls.

renaming columns in Power Query (pivot from pivot)

Step 9: Load the data back to Excel so we can make the pivot

Ok. We are done. Just load the data back to Excel. To do this, go to “Home” ribbon and click on “Close & Load” button.

loading tabular data to Excel

Step 10: Create the Pivot from the loaded data

Once the data is in Excel, just select any cell in the data, go to Insert > Pivot Table (shortcut: ALT N V T) and set up the pivot as per your needs. In my case, I needed the pivot report with number of calls by Day of Week & Representative. So here is how I made it (see the quick video demo).


Things to keep in mind:

The Power Query based approach to create pivot from another pivot is great, but you need to keep a few things in mind.

  • Doesn’t work for averages: If your original pivot table has “averages” instead of “sums”, the new pivot will not be correct. This is because you will make the mistake of “averaging averages”. This technique works great for sums & counts only. Any other measures like average / median / min /max, you need “actual” data to make the new pivot.
  • Power Query steps can get complicated: If your original pivot has a very complex, nested layout, then the PQ steps needed to “transform” data can be complex (but not impossible). I suggest learning how to use Power Query to solve such issues. Refer to this article or video to start your PQ journey.
  • Needs refresh for data changes: If your original Pivot table changes (new values or new rows / columns), you need to update the “pivot_range” named range and refresh the power query data.
    • To update the named range: Go to Formula ribbon in Excel and click on “Name Manager”. Select the name “pivot_range” and edit it. Adjust the cell references as per your newly updated pivot.
    • To Refresh Power Query: Right click on the Power Query data you have loaded in Step 9. Select “Refresh’ to update the loaded data with new changes. Now go to the pivot you made (in step 10) and refresh that too (you guessed it right! Right click and Refresh).

What to do if you get an error (in Power Query):

Errors can happen either during the initial process (steps 3 to 9) or when you refresh the power query connection. Solving the error depends on your exact pivot table layout and what changes were made. But here are the most likely reasons for the error.

  • Column names have changed: You will get error if your columns (in the original pivot) were changed between updates. Adjust the names in the original pivot or go to Power Query editor, locate the step where the error is happening and adjust the names there.
  • Data type issues: If for some reason, your original pivot’s values are read by Power Query as “text”, it can create issues. Right click on the columns with numbers and explicitly convert them to numbers in PQ.
  • Layout changes: If your pivot layout changes (say, instead of 2 columns, it now has 3 columns of row labels), then your refresh will fail. You need to select one more column before unpivoting (step 7).
  • Other issues: Leave a comment with the issue / error you are facing so I can help.

Pivot from Another Pivot – FREE Excel Template

excel template - pivot from pivot

I created a free Excel template to guide you thru the process with sample data. Download it here and understand the process better.

In conclusion:

Power Query in Excel offers an elegant, simple and easy way to deal with the annoying issue of using “pivot tables” as data source. I had plenty of success with this method and I hope will too. If you do have any questions or face issues during the process, leave a comment.

Facebook
Twitter
LinkedIn

Share this tip with your colleagues

Excel and Power BI tips - Chandoo.org Newsletter

Get FREE Excel + Power BI Tips

Simple, fun and useful emails, once per week.

Learn & be awesome.

Welcome to Chandoo.org

Thank you so much for visiting. My aim is to make you awesome in Excel & Power BI. I do this by sharing videos, tips, examples and downloads on this website. There are more than 1,000 pages with all things Excel, Power BI, Dashboards & VBA here. Go ahead and spend few minutes to be AWESOME.

Read my storyFREE Excel tips book

Overall I learned a lot and I thought you did a great job of explaining how to do things. This will definitely elevate my reporting in the future.
Rebekah S
Reporting Analyst
Excel formula list - 100+ examples and howto guide for you

From simple to complex, there is a formula for every occasion. Check out the list now.

Calendars, invoices, trackers and much more. All free, fun and fantastic.

Advanced Pivot Table tricks

Power Query, Data model, DAX, Filters, Slicers, Conditional formats and beautiful charts. It's all here.

Still on fence about Power BI? In this getting started guide, learn what is Power BI, how to get it and how to create your first report from scratch.

40 Responses to “Lost Excel Functions”

  1. Luke M says:

    Of all the functions, I think the BAHTTEXT function is the biggest "Why is this here???"
    It's use would be limited to a very, very small demographic. A better function would have been a generic translate function where you pick the language (even if it was only the top 5 or something...)

  2. Kevin says:

    Lost by whose definition? Some people use these functions(me). There are alot of words in English dictionary that aren't used.

  3. This is a great post, especially because I love Lost. Thanks!

  4. SteveT says:

    Nice Post Hui. It is amazing what is in the program that you have never heard of. I typed in =d and looked at the functions. "Delta" popped out although it is documented, why would you ever use it vs. just comparing with an equal sign (=1=1).

  5. Ninad Pradhan says:

    I use Datedif at times. What will be nice is if alternatives to these "Lost" functions can also be posted with examples. That'll be a good reading and also deter users from using functions "soon to be made obsolete"

  6. OlaSa says:

    I don't think the intersect AND logic is very well documented:
    =B1:B3 A2:C2 One intersection
    =SUM(D9:F9 E8:F10) Two intersections
    =SUM(D9:F9 E8:E10 F8:F10) No intersection --> #NULL! Not seen very often
    There might be a OR logic lurking as well
    //Ola

  7. Fred says:

    Interesting post! 😉

    I found out that only "evaluate" isn't available in my excel 2007.

  8. Prem Sivakanthan says:

    Great post, thanks Hui! 🙂

  9. Hui... says:

    @Fred
    Evaluate is a Excel 4 Macro Function and not a spreadsheet function
    It can only be used in Named Ranges and VBA, not as a spreadsheet function.

    @OlaSa
    I forgot all about the 2 Operators you mention.
    Daniel at Excel Hero has done a story about them at: http://www.excelhero.com/blog/2010/06/which-function-to-use---part-1.html

    @Steve T
    Yes, Delta and Gestep are odd functions and easily replaced with alternative logic.
    These 2 functions may have uses in handling ranges and not just single cells.

  10. juanito says:

    I read somewhere not too long ago (at Daily Dose, possible) that BAHTTEXT is "rumoured" to be a self-interested joke by the MS Excel programmers: although this function would be at least equally useful for other currencies, they did the baht first because they're extremely partial to Thai takeaways and wanted to speed up the turnaround time

  11. Alasdair says:

    ...and why isn't there a reverse ROMAN?

  12. Hi Hui,

    I think you have mis-defined the Result range name because you have made the name relative. The proper formula should have been
    =EVALUATE($A$1).
    NB: I use the technique in this post: http://www.jkp-ads.com/articles/chartanequation00.asp

  13. SteveT says:

    Found this posting with some User Defined Functions and VBA for reversing Roman Numerals:

    http://www.excelbanter.com/showthread.php?t=141566

  14. tra says:

    Hi Hui - Thanks for the post - a little off the excel topic, but wondering what does "you"ll be the full bottle" mean? Have never heard this expression before. 🙂

  15. Hui... says:

    @Tra
    “you'll be the full bottle” is Aussie slang for "You'll know all about it"

  16. Hui... says:

    @Jan Karel Pieterse
    Thanx for the input
    .
    =Evaluate(A1) is ok as long as A1 is the active cell
    It can create problems if it isn't.
    .
    Ideally it should be entered as =EVALUATE(SheetName!$A$1)
    I have updated the post accordingly

  17. Luke M says:

    Further info on DELTA:
    Have 1 cell formatted to number (a1), and the other formatted to text (a2).
    Type the number 1 into both cells
    The formula:
    =A1=A2
    returns FALSE (number does not equal text)
    formula:
    =DELTA(A1,A2)
    returns 1 (the equivalent of true). I see limited places where this would be useful, but wanted to point out that they do function differently.

  18. Hui... says:

    In Excel2010
    I just tried Delta with
    2 2 =Delta(A2, B2) =1
    '2 '2 =Delta(A3, B3) =1
    '2 2 =Delta(A4, B4) =1
    C C =Delta(A5, B5) =#Value!

    Lines 3 & 4 should also give errors but don't ?

    The formatting of the cells shouldn't affect the results as that is just for display

  19. Ed says:

    Great post.

    Interesting that the roman function returns a #value! if you go any higher than 3999

  20. @Chandoo Not trying to be a shameless self promoter (I just want to spread the Excel awesomeness) but I've found an obscure way to create a mouse-over effect in Excel using the Hyperlink() formula and some VBA. I've used this technique in some of my dashboards at work, and as an example of how it's useful, you could use it in the Grammy Bump chart to simply let users rollover a year instead of clicking on it. I talk about it in the latest post of my rarely updated blog which is linked on my name in this post. Or, here's the long and short of it:
    .
    =HYPERLINK(MyFunction(), "Mouseover me!")
    .
    Then in some module:
    Public Function MyFunction()
    Msgbox "hi!"
    End Function
    .
    To test: place your mouse over the underlined portion of the cell. To make the entire-cell a mouse over target (not just the underlined portion), word wrap it. Also, if you want the function to change parts of your spreadsheet, you'll need to wrap the Hyperlink formula in an IFERROR (you'll see what I mean when you try it). Or you can read about it by clicking on my name, either way, make sure to have fun!

  21. Luke M says:

    @Hui
    Seems like DELTA has the advantage in being able to recognize "text as numbers". And yes, thanks for clarifying my statement about formatting. I should have been clearer in the fact that I just wanted to compare a text string with a number...in which case, maybe I should have just written:
    =DELTA(1,"1") 'Results in 1

  22. Chandoo says:

    @Jordan... wow, that is a beautiful trick. I have not yet tested it, but seems like it has lots of potential. Let me play with the idea and may be write a follow-up article on this.

    Btw, you are welcome to share information and links. That is the whole point of commenting. 🙂

  23. SteveT says:

    Alright, i am no engineer, but a simple formula can also do what Delta does without having a whole function for it. That is like creating a function called Add (Syntax =Add(a1,a2) that results in the addition of A1+A2

    This will do what delta does on numbers and textNumbers and its not rocket science or structural engineering 🙂 🙂

    =VALUE(A1)=VALUE(A2) will also yield true/false

    And if you need the result as a number =(VALUE(A3)=VALUE(A4))*1

  24. myckolah says:

    @SteveT
    You know, they invented this function you described in Excel. It is called SUM, not ADD 🙂
    There are also functions PRODUCT, SUMPRODUCT and others. All of them simple definied, and it doesn't mean they aren't to be in Excel.

  25. Doug Jenkins says:

    Of the under-used functions, I think Evaluate is probably the most useful.

    The short UDF presented here:
    http://newtonexcelbach.wordpress.com/2008/04/22/evaluate-function/
    allows Excel to evaluate functions entered as text, without the need to create named ranges.

    An application using this function can be downloaded here:
    http://newtonexcelbach.wordpress.com/2008/03/25/section-properties-of-defined-shapes-spreadsheet/

  26. Jaspal says:

    thanks for this. I hope to use "convert" more frequently henceforth

  27. Andrew says:

    @ruvelk and @Chandoo

    I checked out the link you provided (ruvelk) and the explanation given of the intervals 'MD' 'YM' AND 'YD' provided above (Chandoo) and the information is not quite correct.

    'MD' returns the number of days since the last completed month.
    'YM' returns the number of months since the last completed year.
    'YD' returns the number of days since the last completed year.

    As far as I can see there is no flaw in the function just perhaps a misunderstanding of what is does.

    eg
    using the 'MD' interval
    02/28/2010 to 01/11/2011
    Last completed month = 12/28/2010
    Number of days between 12/28/2010 and 01/11/2011 = 14

    Using 03/01/2010 to 01/11/2011
    Last completed month = 01/01/2011
    Number of days between 01/01/2011 and 01/11/2011 = 10

    Cheers

    Andrew

  28. Hui... says:

    @Andrew
    I think we are talking about the same thing in different ways.

    From the post:
    "md" Days Excluding Years And Months Complete calendar days between the dates as if they were of the same month and same year.

    so using your dates
    28/2/10 to 11/1/11 will count 29, 30 and 31 as if they are in January and then the first 11 days in January = 14 days.
    That is, it is counting the dates as if they are both in January, same year, and so there is 14 days between them.

  29. Chandra SEkhar says:

    Hi,

    Can any one tell how to enter data into range of cells through a single cell without the help of VBA.

    Regards
    Chandra

  30. Phil Bornemeier says:

    @Chandra
    If you type this into A1:
    ={1,2,3;4,5,6;7,8,9}
    then select A1:C3 and use Control+Shift+Enter
    You will get a 3x3 array in A1:C3
    The formula in each cell in that range will be:
    {={1,2,3;4,5,6;7,8,9}}

    Commas separate columns.  Semicolons separate rows,

    This is of limited use since the cells in this array cannot be individually edited.

  31. Phil Bornemeier says:

    There is at least 1 Excel 4 macro that provides functionality that cannot (AFAIK) be replicated in later versions of Excel.  GET.CHART.ITEM is used to get the exact coordinates of chart elements, including the coordinates of individual points in a line graph (or edge and corner cordinates of bars, or columns for those types of graphs).  For example:
    sngXPos = ExecuteExcel4Macro("get.chart.item(1,1, ""S2P" & lX & """)")
    returns the X position of each point in series 2 of a line graph as you iterate from 1 To ActiveChart.SeriesCollection(2).Points.Count

    Documentation file for Excel4 macros available at:
    http://support.microsoft.com/kb/128185

    Excel 2010 has incorporated most (but not all?) of this functionality as described here:
    http://blogs.office.com/b/microsoft-excel/archive/2010/02/16/migrating-excel-4-macros-to-vba.aspx

  32. stansult says:

    Unfortunately, I don’t see Evaluate working in Excel 2010.
    I have Microsoft Office Professional Plus 2010.
    When I try it myself, or download the example file, I have #NAME?
    result in the cell containing “=Result” formula.

  33. […] To know how many months are left between TODAY() and date in A1, use = DATEDIF(TODAY(), A1, “m”). Related: How to use DATEDIF function. […]

  34. […] To know how many months are left between TODAY() and date in A1, use = DATEDIF(TODAY(), A1, “m”). Related: How to use DATEDIF function. […]

  35. Marty says:

    I once ran across an undocumented version of GETPIVOTDATA. The syntax was something like "GETPIVOTDATA($A$3, ...", where $A$# would reference the pivot table then you could concatenate text fields to select the specific data you were after. I found this useful as I could use an IF("condition", "place field text", ""). This way if the "condition" was met it would field data requested otherwise nothing was included. This worked well if nested condition were not available. Hope this is clear. I can't find the alternate syntax for GETPIVOTDATA anywhere. Does someone have it?

Leave a Reply