Here is our problem. When you create a Pivot Table in Excel that has a date field, you can Group that field by month and the sort will be logical (January, February, …). But when you create a Pivot Table based on Power Pivot, the grouping does not work! (This can also happen if no Power Pivot is used). So you have to get to the month names from month numbers and then a correct sorting by using. We get the month names from month numbers by using the Format function in PowerPivot (the PowerPivot equivalent of the Text function in Excel, both are explained further down this post), but the problem is that when you put this field in a Pivot Table, it gets sorted alphabetically. This is logical since the values are text and have nothing to do with dates as far as that Pivot Table is concerned, but this is a problem since the months are not sorted chronologically. This article will tell you how to achieve that in both cases.
Let’s start with a simple table in Excel that has only two columns. One has Date values and the other has a number of visitors on that date. Now we would like to create a Pivot Table report to see how the number of visitors is spread through the months.
First we create a Pivot Table based on an Excel Table
The Pivot Table will show the number of visitors by months. But to do this, since we only have Dates, we have to do Grouping by months on the Dates
And right away we get the desired result.
If that was not the case, we would get the right sort order by sorting those by Custom Lists.
First we add our Table data to Power Pivot the easiest way – by using the Add to Data Model command on the PowerPivot tab.
Now that we have the data in the Power Pivot we can create a Pivot Table report from Power Pivot window. But when we create a Pivot Table and want to see the analysis by months we see we just can’t select the Group command. It is grayed out…
So to get to months we use a different trick, we go back to the Power Pivot window and create a calculated column using a Format function. This is a PowerPivot rendition of the Text function from Excel. The syntax is the same, just the names differ.
Power Pivot version.
Using the Format function we now get the month names and a new field to create a Pivot Report by. But when we create it, it looks quite disappointing.
So the numbers are OK, but the sorting is alphabetical and not the kind we want. To get the sorting right, we have to go back to the PowerPivot window and create a new Calculated column using the Month function. This way we now get a month number along each date and month name.
Now just adding that to the Pivot Table report would get rid of our problem, but let’s not forget that we want the month names as they were, only the sorting is wrong. But now we have all we need.
In the Power Pivot window, we select a value in the month name column and then select a Sort by Column command on the home tab and hey, look at that. You can now say that the Month name column will be sorted by Month No. column.
Doing that has changed our Pivot Report instantly!
And we are one step closer to eternal happiness.
Probably the longest title of all times, but it leads to ...
If some pictures are hard to view, you can get the PDF of the ...
One might think that analyzing data with a Pivot table is hard, ...
This is the second article of three. If you hadn’t read the ...