Editor’s note: The following post was written by Excel MVP Zack Barresse
Let’s explore a new feature of Excel 2013 called Timelines. In this blog post we will cover what they are, what you can do with them and how to create your very first Timeline. They are one of the best additions to this latest version of Office. Once you create one and start using them you’ll never want to use anything else.
Timelines are a new addition to Excel 2013. They are a kind of slicer, or visual filter, for dates. These new controls give you an extreme amount of flexibility when wanting to filter a PivotTable by date. Filtering by dates has got better with every version and in 2013 it’s easier than ever. Unfortunately you can only filter a PivotTable with these controls, it will not work on standard tables. There is no special add-in required to use these features, they ship out-of-the-box in Excel 2013.
These controls also persist into the Excel Web App (as do slicers), which means if you view/open your file in SkyDrive you will still have access to utilize these controls. This is a great benefit when looking at the continuity of experience from desktop to web app.
You can assign a timeline to a PivotChart as well, as it’s based on a pivot (data) cache.
Quite simply – they filter. Timelines are the best date filters you’ve ever used. Traditionally there has been date filtering (i.e. clicking the filter drop-down arrow on a PivotTable and you can filter by year, quarter, month, day, etc.), and like slicers these are great visual representations of those filtering capabilities, allowing you to easily see what date range has been filtered, as well as add a nice aesthetic to your worksheet.
For the remainder of this post I’m going to be using one of the many beautiful templates Microsoft has to offer (for free), the Budget for fundraiser event, found through Excel (internet connection required), or through Microsoft’s office.com. Another reason I’m using this template as my example is there are PivotTable’s and the data source has a date field. Two requirements for implementing timeline controls.
Step 1 – Start with a Pivot Table If you’ve downloaded the template used in this post you’ll probably notice the PivotTable’s (there are two on the EVENT OVERVIEW sheet) only have the DATE field in the FILTERS area. If you click the filter drop-down arrow you will see a list of all unique items which are in that field in the data source (as seen below).
This is a pretty standard autofilter. If you don’t want to use the template in this example, ensure your PivotTable data source has a date field and you’ll be good to go.
NOTE: All filtering you can achieve natively (as you’ve always done) can be done through a timeline with one caveat – you cannot select a non-contiguous date range, it must be contiguous. This means that you can only select a start and end date to filter for. For non-contiguous date ranges you must use manual filtering and check the box ‘Select Multiple Items’ (as pictured above).
Step 2 – Insert a Timeline With any cell in a PivotTable selected you will get the PIVOTTABLE TOOLS ribbon tab to appear. If you’re not familiar with this it’s called a contextual tab, in that it won’t be visible on the ribbon unless you’ve selected its object. Some other contextual tabs are shown for tables, charts, slicers, timelines, etc. When you select a PivotTable cell, you will see the following ribbon tab:
In the Filters group of this tab you will see three controls: Insert Slicer, Insert Timeline, and Filter Connections. Slicers were introduced in Excel 2010 for PivotTable’s only. In Excel 2013 we now have the same ability but it’s now available for use with tables. Filter Connections lets you assign which slicers you set to which PivotTable’s. This can be very handy if you have multiple Slicers you want to filter a multiple PivotTable’s which have the same data source. For today we’ll focus on the Insert Timeline button.
When you click on Insert Timeline you will be presented with dialog box which shows all fields in your data source which contain a date or time field as analyzed by Excel (no text-formatted dates allowed).
NOTE: While you can add a timeline for a time field, you will still only have the options available for filtering individual days, not any time increments within a day.
Check the box for the field you want a timeline control added for. When you click OK you will see your timeline appear.
As with slicers, when you have a timeline selected you will see a contextual ribbon tab appear giving you additional options to customize your new control.
There are only five groups of controls. As with slicers, the Report Connections let you tie a single filter control to multiple PivotTable’s which are based on the same source data. It will not work with multiple PivotTable’s with different data sources.
Step 3 – Customize Your Timeline There are various parts of these controls you should become familiar with. All of which you can customize to some extent. There are four parts of the physical structure of the control.
You can toggle these parts visibility on or off with the ‘Show’ group controls on the TIMELINE TOOLS contextual ribbon tab. This will toggle the visibility of that part.
The standard ‘Arrange’ and ‘Size’ group controls accompany timeline controls as well, which lets you move objects backwards and forwards, as well as align controls to your desire.
As with slicers, tables and PivotTable’s, you have a styles gallery group as well. If you want control over all parts of how your timeline looks and feels, you have many options to format your controls the way you want. As with other style galleries, you have the option to setting any one of them as the default for the workbook by right-clicking that style and choosing ‘Set As Default’. This way when you create a new timeline it will have the style applied you like best.
Using timelines is as easy as point and click. When looking at the control you will see the filtered range colored, with each end containing a vertical ellipses, which you can click and drag to where you want (as seen below). In addition you can click any time segment seen in the control.
Your filtered data range will be shown in the Selection Label area. Too granular or course? Change the Time Level by clicking on it, where you get a drop down to choose from years, quarters, months and days. These are not customizable.
Controlling these with code is possible too. While this is a whole other topic, let’s briefly cover the basics. Timelines are in fact a type of slicer and can be handled as such with VBA. In the VBA example below it will require you to pass a valid slicer object to it. Slicers are objects which can be set from a PivotTable (attached to a data cache). To tell a timeline apart from a regular slicer you can check the slicer’s cache type. Here is a simple function to check what type of slicer you’re dealing with:
Function TypeOfSlicer(ByVal SlicerCheck As Slicer) As String '--------------------------------------------------------------------------------------- ' Procedure : TypeOfSlicer ' Author : Zack Barresse ' Date : 7/11/2013 ' Purpose : Check the type of slicer passed. '--------------------------------------------------------------------------------------- On Error Resume Next If SlicerCheck.SlicerCacheType = xlSlicer Then TypeOfSlicer = "Slicer" If SlicerCheck.SlicerCacheType = xlTimeline Then TypeOfSlicer = "Timeline" If TypeOfSlicer = vbNullString Then TypeOfSlicer = "ERROR!" On Error GoTo 0 End Function
The SlicerCacheType will give you an enumerated constant of the type of slicer it is. Timelines have their own members in the object library.
Customizing your timeline in VBA boils down into two distinct objects: TimelineState and TimelineViewState. Most methods can be found in these two objects.
TimelineState This is a child object of the slicer cache. You would use this to set the date range, check the start and end date currently filtered, etc.
TimelineViewState This is a direct child object of the slicer itself. This object will give you options for its viewing state, or how it looks and appears.
Timeline controls are visual representations of filters, like a slicer, but specifically designed for dates. You may copy and paste a timeline control as many times as you would like, and may tie them all to a single PivotTable (data cache). For example if you want a separate timeline for years and months, it’s as easy as copy and paste. Have multiple PivotTable’s based on the same data source? No problem, connect your timeline controls to the same Report Connection, just as you would a slicer (in addition to copy and paste). The following timelines are all tie to the same PivotTable and filter in unison. Change one and they all update.
Thanks to the Excel team for creating such beautiful slicer types!
About the author
Zack Barresse lives in Oregon with his family where he likes to go camping, fishing, playing Xbox and spending time with his family. His other love is Excel, which he has been using since December 2003. In 2005 Microsoft recognized him with the MVP award and he has been awarded every year since. Zack maintains helping others in Excel through social media, blogs, has been technical editor of the Missing Manual: Excel series since 2007 and is authoring his first book. Being self-taught in Excel he tried to help others wherever he can. Follow him on Twitter.
About MVP Mondays
The MVP Monday Series is created by Melissa Travers. In this series we work to provide readers with a guest post from an MVP every Monday. Melissa is a Community Program Manager, formerly known as MVP Lead, for Messaging and Collaboration (Exchange, Lync, Office 365 and SharePoint) and Microsoft Dynamics in the US. She began her career at Microsoft as an Exchange Support Engineer and has been working with the technical community in some capacity for almost a decade. In her spare time she enjoys going to the gym, shopping for handbags, watching period and fantasy dramas, and spending time with her children and miniature Dachshund. Melissa lives in North Carolina and works out of the Microsoft Charlotte office.
Great post Zack. Wonderful level of detail, and nice graphics.
I'm really confused about some problem. I did a pivot table with slicers in Excel 2013, and very worried cause i can't used it in excel 2010! and not all my users can change their version. I'm getting this message:
"This pivot table was created in a later version of Excel and can't be updated in this version. To update it, click OK, and then open the workbook in the version of Excel it was originally created in."
How can I move the timeline slicer to the current date every time a data is refresh from sql connection.
Is it possible to grab the selection label to use in a cell or as a subtitle of a graph?