Forcing Number Formatting in a Pivot Table

July 20, 2009 by datapig Leave a reply »

Every now and then, I have to deal with a situation where a normalized dataset makes it difficult to build an appropriate pivot table.

Here’s an example:

This dataset contains metrics information for each Market.

Notice a column that identifies the Measure, and a column that specifies the corresponding Value.

Although this is generally a nicely formatted table, you’ll notice that some of the measures are meant to be Number format while others are meant to be Percentage.

In the database where this dataset originated, the Values field is a ‘Double’ data type, so this works.

The problem is that when you create a pivot table out of this dataset, you can’t assign two different number formats for the Values field. After all, one field – one number format.

So in this example, trying to set the number format for the percentage measures will also change the format for the measure that are supposed to be straight numbers.

My solution was to apply a custom number format that formats any value greater than 1.5 to a number. Any value less than 1.5 will be formatted as a Percent.

Here is the syntax I used: [>=1.5]#,##0;[<1.5]0.0%

The result is that each Measure is now formatted appropriately.

Obviously I got a little lucky with the parameters of the situation here. This wouldn’t work in all scenarios. But this techniques does open some options .

RELATED STUFF

  1. Creating a Frequency Distribution with a Pivot Table
  2. Exploding a Dataset using a PivotTable
  3. Cut the Size of Your Pivot Table Workbooks in Half
Advertisement

5 Responses

  1. Michael Pennington says:

    Very clever, sir. It’s no bacon mayo, but it is pretty damn clever.

  2. Raph says:

    My first visit to this site and I found the first post to be useful! Great tip. Thanks!

  3. jeff weir says:

    Great idea, but I first came across it on the Enron blog.

  4. General Ledger says:

    I had no idea you could do such a value comparison in a custom number format. I was only taught that you had posivite, negative, zero and label segments in number formats.

    I don’t know if I will ever have a situation to use it, but still a great tip that could be priceless.

  5. Nintendo DS says:

    Need to subscribe to this blog, great post. Found it on google.

Leave a Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

*

* Copy this password:

* Type or paste password here:

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>