Tuesday, June 24, 2014

Everything in its Place


The Problem

“Is there an easy way to fully expand and fully collapse my pivot chart?” or its cousin,“Can I just press a button to get the pivot chart back to a default?”
These are relatively frequent questions that I never had fully satisfactory answers for.
Before we get into the tip, I used to recommend Right Click à Collapse All or Right Click à Collapse Dimension Columns to collapse the chart and Right Click à Expand All to expand columns (one-by-one).

That solution is not great because first, if you are expanding the chart all the way out, you still have to do it one column at a time.  But the biggest problem presents once you pivot a dimension horizontally.  At that point, you cannot collapse the pivoted column without first un-pivoting the column.

Solution – The Layout Bookmark

The solution to this is actually pretty neat.  It involves a special kind of bookmark – The Layout Bookmark.  Our example will simply involve a collapsed state and a fully expanded and pivoted year column state.

First create a pivot chart and manipulate the columns so that none are pivoted and all are collapsed. 

Then we simply create a document bookmark Bookmarks à Add Bookmarks as follows.


Notice that we have unchecked “Include Selections in Bookmark”.  We want to be able to invoke this bookmark without affecting the current selections.  The only thing this bookmark will change will be the “layout state” of the application.
Next, expand out all the columns and then pivot the year column horizontally. 

Create another layout bookmark.
Now we need to create a couple buttons that will simply invoke each of these layout bookmarks.  But first, we need to know the id’s.  Go to Bookmarks à More…

There you can see that the id’s for these bookmarks are BM01 and BM02.  Take note of them.
Finally, create the buttons. 
You can name the button whatever you want and then for the button action, use Bookmark à Apply Bookmark along with the id for the bookmark you with to trigger.
Here is the finished product.  Hitting the buttons will expand or collapse the chart to the desired setting.


There are some complications to be aware of when creating layout bookmarks.
·         The layout state affects the entire sheet.  When you create a layout bookmark, it is taking a snapshot of the entire sheet layout, not just the pivot chart you are concerned with.  This includes minimize/restored settings and cyclic dimensions for all objects within the sheet.

·         The layout state activates the sheet.  This means that if you put this button on a different sheet, it will activate the sheet the bookmark was created on.  This could be good or bad but is important to understand for your use-case.

·         Layout states are hidden in containers.  If your charts are in a container, the layout state for objects within the container will not be saved.


Some of the other things that might be done using layout bookmarks.
·         Default sheet state
·         Set a cyclic dimension to be shown
·         Set a grouped expression to be shown
·         Set restored or minimized objects on a sheet
·         Set which object is shown within a single style container
I would love to hear any other ideas you have for this concept or other feedback.  Happy Qliking.


No comments:

Post a Comment