Buy the book: Power Excel With MrExcel - 2017 Edition Book
Ken is creating some rainfall statistics. Which months had the most or least rainfall or rain days? This episode shows how to use a pivot table in Excel to create the reports.
Pivot tables created in 2013 can't be refreshed in 2007
You need to create the pivot table in 2007 to allow it to be refreshable
Goal is to find the five months with the least rainfall
Create a large pivot table with rainfall by month
Sort by rainfall ascending
Change to Tabular Form
Use the Value Filters, Top 10, to get the bottom 5!
Remove the Grand Total row
Note that a tie might cause this report to give you 6 or more rows
Once you have the first pivot table, copy it into place and create next pivot table
When you change from one value field to another, you have to re-do the sort and filter
When you change from one row field to another, you have to re-do the sort and filter
Bonus tip: creating a pivot table with rows and columns
Ken is creating some rainfall statistics. Which months had the most or least rainfall or rain days? This episode shows how to use a pivot table in Excel to create the reports.
Pivot tables created in 2013 can't be refreshed in 2007
You need to create the pivot table in 2007 to allow it to be refreshable
Goal is to find the five months with the least rainfall
Create a large pivot table with rainfall by month
Sort by rainfall ascending
Change to Tabular Form
Use the Value Filters, Top 10, to get the bottom 5!
Remove the Grand Total row
Note that a tie might cause this report to give you 6 or more rows
Once you have the first pivot table, copy it into place and create next pivot table
When you change from one value field to another, you have to re-do the sort and filter
When you change from one row field to another, you have to re-do the sort and filter
Bonus tip: creating a pivot table with rows and columns
Transcript of the video:
Learn Excel from MrExcel Podcast, Episode 2063: The Top or Bottom Five Months or Years Using A Pivot Table.
Hey, welcome back to the MrExcel netcast, I’m Bill Jelen.
Today's question sent in by Ken.
Ken has an amazing spreadsheet here with years and years and years of daily rainfall dates, going back to 1999.
A really impressive collection of data that he has, and Ken had some amazing formulas to try and find the month with the most rainfall, at least rainfall.
So now, you know, this will be a lot easier with a pivot table.
Alright now, Ken's never created a pivot table and to further complicate things, I’m here in Excel 2016, Ken's using Excel 2007.
My pivot tables that I created in 2016, he could see him but he couldn't refresh them.
Alright, so this video is Pivot Table 101: How to create your first pivot table.
First, Ken have this Date in Column A, real dates, are we good?
That's awesome, right?
And then I use- insert a couple of extra formulas here at the =YEAR function to get the year, =MONTH function to get the month, =DAY function.
And then concatenate those back together, I actually used the =TEXT function in YYYY-MM, that way I have year and month down.
This is Ken's data, the rain data here and then I added some formulas.
Ken’s has anything less than .5 millimeters, doesn't count as a rain day so there's a formula there.
And then, from Episode 735, go back and take a look at that to see how I calculated the streak of days with rain and streak of days without rain.
Now that's not going to be used today, that was used for something else.
So, we come here.
And first, we want to select the data for our pivot table.
Now, in most cases, you could just select all data so you could just choose one cell here but in this case, there's a Name range that defines the data just through, in this case, 2016.
We're sitting here- I’m recording this at the beginning of 2017.
Ken’s data only goes through the end of 2016.
So, we're going to select just that data.
And then on the Insert tab- Insert tab.
Excel 2007, it’s the first time the pivot tables move from the Data tab back to the Insert tab.
So we choose: Pivot Table, and our selected data is going to be the data that we build from.
And, we don't want to go to new worksheet, we're going to go to an existing worksheet and I’m going to put that right over here in Column - let's go with the Column N.
Now ultimately, I want this data Years with the Lowest Rainfall to appear right here but I know that as I’m building this pivot table, it's going to need a lot more rows than those 5, right?
So, I’m building it off to the side here, alright.
And we click OK.
Alright, now here's what you get.
This is where the report is going to go and here's a list of all the fields we have in our little data set.
And then we have, for what I call horribly named drops out.
Rows is the items you want down the left-hand side.
Values is the thing that you want to sum up and then Columns are the things you want across the top.
We might use this at the end.
We're not going to use Filters today.
So, we're just building a simple little pivot table with total rainfall by year, so I take the Year field and drag it down here to the left-hand side.
There's a list of all of our years, alright?
And then, think about it.
To get this formula here without a pivot table, you'd be doing what?
SUMIF, oh yeah, SUMIF.
You could even use SUMIF’s back in Excel 2007.
So, I’m going to take the Rain field and drag that here.
Right now watch out for the – See, they chose Count of Rain, that's because there's a few days in the data or Ken has a blank cell, an empty cell instead of a 0.
And yeah, we should go through and fix that but it's Ken's data.
It's 20 years worth of data.
I’m not going to go through even using Find & Replace.
Alright, I’m just- For whatever reason I’m going to respect that Ken has a reason to have those, like I’m going to allow them to stay blank.
And here, under Count of Rain, I’m going to make sure to choose a cell in the Count of Rain column, go to Field Settings, and change that from Count to Sum, alright?
So there is all of our years and how much rain we had in each year.
And we're looking for the years with the lowest rainfall.
Alright now, one thing that bugs me is this word here Row Labels.
That started happening to us in Excel 2007, alright?
And I - 10 years later I still despise that.
I go to the Design Tab, open Report Layout and say Show in Tabular Form, and all that does.
In this particular case is get a real heading there of Year, right?
And I prefer the real heading.
Right now, we want to see just the top or in this case, the Years with the Lowest Rainfall.
So I’m going to sort this data ascending.
Now there's two ways to do this.
You could open this drop-down, go to More Sort Options, choose To sending based on sum of rain, but it's also possible just to come here into Data, A to Z to get things sorted from lowest to highest.
But I don't want to see just the top 5 years, so the Years with the Lowest Rainfall, I come here to the Year heading, open this little drop-down and choose Value Filters.
And I’m looking for Bottom 5.
Well, there is no filter for Bottom 5.
Ahh, but this one for top ten is incredibly powerful.
Alright, it doesn't have to be top.
It can be top or bottom.
It doesn't have to be 10; it can be 5.
So, ask for the Top 5 Items based on sum of rain, click OK.
And there is our report.
Now in this case, it would be really highly unusual if we had exactly 2 years with 767.7 inches or millimeters of rain exactly, right?
Just not going to happen.
But you have to be cognizant of the fact that when you asked for the Top 5, if there is a tie for that position, you might get a sixth row.
If there's a 3-way tie, you might get a seventh row.
Alright, so just be prepared for that.
Grand total here really makes no sense since we're showing just the Top 5, and they're not even 5 consecutive years.
So I’m going to right-click on the word Grand Total and say Remove Grand Total.
Remove Grand Total.
I’m wondering if that was there in Excel 2007.
If it's not there in Excel 2007, go to the Design tab, Grand Totals, Off for Rows and Columns.
We’ll do the same thing, alright.
So now that we have this first pivot table and it's sized correctly, I’m going to copy that pivot table, Ctrl+C, make sure to choose the entire pivot table and go there - Years with Lowest Rainfall.
Now another thing that Ken wants is the years with highest, highest rainfall.
Alright, so in this case, we're going to Sort the data, Z-A descending.
And then here, come back into the Value Filters, go back into Top 10 and simply change it from Bottom to Top, click OK.
Alright, so once you get the first pivot table built, pivot tables are so flexible.
It's incredible how easy it is to just keep changing the pivot table.
Alright now, here's the- here's the gotcha, right.
The thing that makes us a little bit difficult.
Now we want to look at the years with the least number of rain days, alright.
How many days do we have- the fewest number of days with rain?
Alright, so now this is going to change the pivot table a little because I want to take the Sum of Rain out, and I’m going to replace it with Rain Day.
Alright, and see that one automatically came in as sum because my formula here is always returning a numeric values.
We didn't have to change it to Account.
And we're looking for the years with the least rain day so we're going to sort this ascending, alright, so that gets our sort back in but we've lost the Value Filter, the Top 5.
Because we took the field that it was using, Rain out.
So we have to reapply that: Value Filters and say Top – Actually we want the bottom, with the Bottom 5, like that.
Alright, so every time that I take a field in or out over here in the Values area, you have to be prepared to redo the Sort and redo the Filter.
So Ctrl+C to copy that and paste right here, Years with the Least Rain Days.
Now, Ken has a lot of other statistics.
I'll leave this up to Ken how to do this, but see here when we change the months, months with the highest rainfall.
Alright, so now, I’m going to be changing a field in the row area.
So we take Year out, put the Month field in like that and then this goes back to Rain, instead of Rain Days we put Rain in.
Again, they forgotten that we want a sum so you have to go back in.
In 2007, it’s called the Analyze tab, it's the first pivot table tools tab.
Go to Field Settings, choose something like that – beautiful.
And what are we looking for?
We're looking for the months with the highest rainfall.
So we're going to Sort Descending: Data, Z to A, and then again here, go back in to the Value Filters, Top 10 and we will ask for the Top 5 like that, alright?
So very, very flexible.
You can figure out the months with the least rain days, the most rain days and so on.
So copy here, Ctrl+C and come and paste.
Now, one of the thing that Ken was building, he’s building a beautiful master table.
It took this daily data and summarized it by year and month.
So, let's just do that.
Let's put Years down the left-hand side like this.
Year's down the left-hand side, I got lazy there.
I tried to check Market, it went to the wrong spot.
We have some rainfall but we want to see months going across.
And I know I have some other data out here to the right so I’m just going to insert a whole bunch of extra columns.
Insert columns that way, I know that my pivot table won't crash into that.
Beautiful thing here that Month field, the 1 through 12, I take that, drag it to the columns.
And I now have a report showing years down the side, months going across the top and the summary of how much rain we had in each one.
Those pivot tables are just an amazing, amazing feature.
Alright, if you're new to pivot tables, my new book, Power Excel with MrExcel.
This book hit the bookstores January 1st , what about - 36 days ago.
But the new e-book versions for the Kindle, for your iPad, and we are PDF.
Those are all now available at MrExcel.
If you buy the book from me, if you buy the print book for me, you get all 3 of those eBook formats for free.
Minor have no DRM, no hassles.
We believe in no hassles.
You buy the book, you get all the formats.
And what’s - Click the link down there in the YouTube description to get to my page where you can buy that book.
So wrap- up: Pivot tables created in Excel 2013 or 2016, can’t be refreshed in 2007.
You have to create the pivot table in 2007 to allow it to be refreshable.
So our goal is to find the five months with the least rainfall.
Created a large pivot table with a rainfall by month, I knew that was going to fit in more than five rows.
I built it off to the side.
Sort by rainfall, actually, ascending is what we did here.
Change the tabular form and then open that drop-down in the first column using the Value Filters, Top 5.
It’s weird, you asked for the Top 10 and you get the bottom 5.
Took the Grand Total row out.
Even though we're asking for 5, you might get 6 if there's ever a tie – 6 or 7.
And then, once we have the first pivot table, copied it into place and then created the next pivot table and just kept doing that.
Although couple of gotchas when you change from one value field to another, you have to redo the Sort & Filter.
You might have to redo the Count to Sum.
When you change from one row field to another you have to redo the Sort & Filter.
And then, right there at the end, showed you how to create a pivot table with rows and column, alright.
Well, hey, I want to thank Ken for sending that question in.
I want to thank you for stopping by.
We'll see you next time for another netcast from MrExcel.
Hey, welcome back to the MrExcel netcast, I’m Bill Jelen.
Today's question sent in by Ken.
Ken has an amazing spreadsheet here with years and years and years of daily rainfall dates, going back to 1999.
A really impressive collection of data that he has, and Ken had some amazing formulas to try and find the month with the most rainfall, at least rainfall.
So now, you know, this will be a lot easier with a pivot table.
Alright now, Ken's never created a pivot table and to further complicate things, I’m here in Excel 2016, Ken's using Excel 2007.
My pivot tables that I created in 2016, he could see him but he couldn't refresh them.
Alright, so this video is Pivot Table 101: How to create your first pivot table.
First, Ken have this Date in Column A, real dates, are we good?
That's awesome, right?
And then I use- insert a couple of extra formulas here at the =YEAR function to get the year, =MONTH function to get the month, =DAY function.
And then concatenate those back together, I actually used the =TEXT function in YYYY-MM, that way I have year and month down.
This is Ken's data, the rain data here and then I added some formulas.
Ken’s has anything less than .5 millimeters, doesn't count as a rain day so there's a formula there.
And then, from Episode 735, go back and take a look at that to see how I calculated the streak of days with rain and streak of days without rain.
Now that's not going to be used today, that was used for something else.
So, we come here.
And first, we want to select the data for our pivot table.
Now, in most cases, you could just select all data so you could just choose one cell here but in this case, there's a Name range that defines the data just through, in this case, 2016.
We're sitting here- I’m recording this at the beginning of 2017.
Ken’s data only goes through the end of 2016.
So, we're going to select just that data.
And then on the Insert tab- Insert tab.
Excel 2007, it’s the first time the pivot tables move from the Data tab back to the Insert tab.
So we choose: Pivot Table, and our selected data is going to be the data that we build from.
And, we don't want to go to new worksheet, we're going to go to an existing worksheet and I’m going to put that right over here in Column - let's go with the Column N.
Now ultimately, I want this data Years with the Lowest Rainfall to appear right here but I know that as I’m building this pivot table, it's going to need a lot more rows than those 5, right?
So, I’m building it off to the side here, alright.
And we click OK.
Alright, now here's what you get.
This is where the report is going to go and here's a list of all the fields we have in our little data set.
And then we have, for what I call horribly named drops out.
Rows is the items you want down the left-hand side.
Values is the thing that you want to sum up and then Columns are the things you want across the top.
We might use this at the end.
We're not going to use Filters today.
So, we're just building a simple little pivot table with total rainfall by year, so I take the Year field and drag it down here to the left-hand side.
There's a list of all of our years, alright?
And then, think about it.
To get this formula here without a pivot table, you'd be doing what?
SUMIF, oh yeah, SUMIF.
You could even use SUMIF’s back in Excel 2007.
So, I’m going to take the Rain field and drag that here.
Right now watch out for the – See, they chose Count of Rain, that's because there's a few days in the data or Ken has a blank cell, an empty cell instead of a 0.
And yeah, we should go through and fix that but it's Ken's data.
It's 20 years worth of data.
I’m not going to go through even using Find & Replace.
Alright, I’m just- For whatever reason I’m going to respect that Ken has a reason to have those, like I’m going to allow them to stay blank.
And here, under Count of Rain, I’m going to make sure to choose a cell in the Count of Rain column, go to Field Settings, and change that from Count to Sum, alright?
So there is all of our years and how much rain we had in each year.
And we're looking for the years with the lowest rainfall.
Alright now, one thing that bugs me is this word here Row Labels.
That started happening to us in Excel 2007, alright?
And I - 10 years later I still despise that.
I go to the Design Tab, open Report Layout and say Show in Tabular Form, and all that does.
In this particular case is get a real heading there of Year, right?
And I prefer the real heading.
Right now, we want to see just the top or in this case, the Years with the Lowest Rainfall.
So I’m going to sort this data ascending.
Now there's two ways to do this.
You could open this drop-down, go to More Sort Options, choose To sending based on sum of rain, but it's also possible just to come here into Data, A to Z to get things sorted from lowest to highest.
But I don't want to see just the top 5 years, so the Years with the Lowest Rainfall, I come here to the Year heading, open this little drop-down and choose Value Filters.
And I’m looking for Bottom 5.
Well, there is no filter for Bottom 5.
Ahh, but this one for top ten is incredibly powerful.
Alright, it doesn't have to be top.
It can be top or bottom.
It doesn't have to be 10; it can be 5.
So, ask for the Top 5 Items based on sum of rain, click OK.
And there is our report.
Now in this case, it would be really highly unusual if we had exactly 2 years with 767.7 inches or millimeters of rain exactly, right?
Just not going to happen.
But you have to be cognizant of the fact that when you asked for the Top 5, if there is a tie for that position, you might get a sixth row.
If there's a 3-way tie, you might get a seventh row.
Alright, so just be prepared for that.
Grand total here really makes no sense since we're showing just the Top 5, and they're not even 5 consecutive years.
So I’m going to right-click on the word Grand Total and say Remove Grand Total.
Remove Grand Total.
I’m wondering if that was there in Excel 2007.
If it's not there in Excel 2007, go to the Design tab, Grand Totals, Off for Rows and Columns.
We’ll do the same thing, alright.
So now that we have this first pivot table and it's sized correctly, I’m going to copy that pivot table, Ctrl+C, make sure to choose the entire pivot table and go there - Years with Lowest Rainfall.
Now another thing that Ken wants is the years with highest, highest rainfall.
Alright, so in this case, we're going to Sort the data, Z-A descending.
And then here, come back into the Value Filters, go back into Top 10 and simply change it from Bottom to Top, click OK.
Alright, so once you get the first pivot table built, pivot tables are so flexible.
It's incredible how easy it is to just keep changing the pivot table.
Alright now, here's the- here's the gotcha, right.
The thing that makes us a little bit difficult.
Now we want to look at the years with the least number of rain days, alright.
How many days do we have- the fewest number of days with rain?
Alright, so now this is going to change the pivot table a little because I want to take the Sum of Rain out, and I’m going to replace it with Rain Day.
Alright, and see that one automatically came in as sum because my formula here is always returning a numeric values.
We didn't have to change it to Account.
And we're looking for the years with the least rain day so we're going to sort this ascending, alright, so that gets our sort back in but we've lost the Value Filter, the Top 5.
Because we took the field that it was using, Rain out.
So we have to reapply that: Value Filters and say Top – Actually we want the bottom, with the Bottom 5, like that.
Alright, so every time that I take a field in or out over here in the Values area, you have to be prepared to redo the Sort and redo the Filter.
So Ctrl+C to copy that and paste right here, Years with the Least Rain Days.
Now, Ken has a lot of other statistics.
I'll leave this up to Ken how to do this, but see here when we change the months, months with the highest rainfall.
Alright, so now, I’m going to be changing a field in the row area.
So we take Year out, put the Month field in like that and then this goes back to Rain, instead of Rain Days we put Rain in.
Again, they forgotten that we want a sum so you have to go back in.
In 2007, it’s called the Analyze tab, it's the first pivot table tools tab.
Go to Field Settings, choose something like that – beautiful.
And what are we looking for?
We're looking for the months with the highest rainfall.
So we're going to Sort Descending: Data, Z to A, and then again here, go back in to the Value Filters, Top 10 and we will ask for the Top 5 like that, alright?
So very, very flexible.
You can figure out the months with the least rain days, the most rain days and so on.
So copy here, Ctrl+C and come and paste.
Now, one of the thing that Ken was building, he’s building a beautiful master table.
It took this daily data and summarized it by year and month.
So, let's just do that.
Let's put Years down the left-hand side like this.
Year's down the left-hand side, I got lazy there.
I tried to check Market, it went to the wrong spot.
We have some rainfall but we want to see months going across.
And I know I have some other data out here to the right so I’m just going to insert a whole bunch of extra columns.
Insert columns that way, I know that my pivot table won't crash into that.
Beautiful thing here that Month field, the 1 through 12, I take that, drag it to the columns.
And I now have a report showing years down the side, months going across the top and the summary of how much rain we had in each one.
Those pivot tables are just an amazing, amazing feature.
Alright, if you're new to pivot tables, my new book, Power Excel with MrExcel.
This book hit the bookstores January 1st , what about - 36 days ago.
But the new e-book versions for the Kindle, for your iPad, and we are PDF.
Those are all now available at MrExcel.
If you buy the book from me, if you buy the print book for me, you get all 3 of those eBook formats for free.
Minor have no DRM, no hassles.
We believe in no hassles.
You buy the book, you get all the formats.
And what’s - Click the link down there in the YouTube description to get to my page where you can buy that book.
So wrap- up: Pivot tables created in Excel 2013 or 2016, can’t be refreshed in 2007.
You have to create the pivot table in 2007 to allow it to be refreshable.
So our goal is to find the five months with the least rainfall.
Created a large pivot table with a rainfall by month, I knew that was going to fit in more than five rows.
I built it off to the side.
Sort by rainfall, actually, ascending is what we did here.
Change the tabular form and then open that drop-down in the first column using the Value Filters, Top 5.
It’s weird, you asked for the Top 10 and you get the bottom 5.
Took the Grand Total row out.
Even though we're asking for 5, you might get 6 if there's ever a tie – 6 or 7.
And then, once we have the first pivot table, copied it into place and then created the next pivot table and just kept doing that.
Although couple of gotchas when you change from one value field to another, you have to redo the Sort & Filter.
You might have to redo the Count to Sum.
When you change from one row field to another you have to redo the Sort & Filter.
And then, right there at the end, showed you how to create a pivot table with rows and column, alright.
Well, hey, I want to thank Ken for sending that question in.
I want to thank you for stopping by.
We'll see you next time for another netcast from MrExcel.