Tableau Quick Tip #2 – Custom Number Formats

How to use Tableau Software’s Custom Number Formats

Intro Custom Number FormatsTableau provides a variety of built-in number and date formats. There are the standard formats “numbers”, “currency”, “scientific” and “percentage”. For scientific and percentage you can only change the decimal places, but for numbers and currencies you can also define the way negative values are displayed, the displayed units, the thousand separator and you can add a prefix and/or suffix to the number. For date fields, Tableau offers 17 different standard formats.

Tableau’s built-in number and date formats will meet most of your requirements. From time to time, however, you need something different. E.g. you want to see “Quarter” instead of “Q” on your date axis, you want to display numbers in hundreds or you need to add some text to the numbers displayed. This is where Tableau’s Custom Number Formats come into play. Today’s post provides some links to learn the principles and the syntax, includes some examples and discusses Tableau’s limitations compared to Microsoft Excel.

Tableau’s Custom Formats

The Tableau Software Manual states:

“Custom: Type in the format you want to use.
This format can be specified by an Excel style number code.”

Well, I think there is no need to go into the details here. There are tons of how-to-tutorials on Microsoft Excel’s Custom Number Formats. Here are just 2 links to get you started: Microsoft Office Excel Custom Formats or Ozgrid: Excel Custom Formats.

Except for some limitations (see below), the principle and the syntax are exactly the same with Tableau. If you aren’t already familiar with Custom Number Formats in Excel, simply refer to one of the links provided for Excel.

Examples

Here is an arbitrary selection of examples:

Add text next to the numbers: "Profit:" #,##0.00;"Loss:" -#,##0.00;
Replace the numbers by text: "Profit";"Loss"
Numbers in tens: 0"."0;-0"."0
Numbers in hundreds: 0"."00;-0"."00
Numbers in trillions: #,##0,,,,.00T;-#,##0,,,,.00T
Show only positive values: #,##.0; ;
Show only negative values: ; -#,##.0;
Add leading zeros to a number: #,### 000000000
Split numbers into dollars and cents: #,## "USD &" .00 "Ct"; – #,## "USD &" .00 "Ct"
Add symbols: #,##0º
Show Quarter instead of Q: yyyy "Quarter" q
Times instead of dates: hh:mm:ss
Only the months: mmmm
Show the full date and am/pm time: ddd, mm/dd/yyyy, hh:mm am/pm
Special syntax like telephone numbers: (###) ###-###-###
Don’t show anything at all: ;
(I am not sure why you should want to hide everything, but you never know.)  

How to get familiar with the concept

If you are not yet familiar with the concept of Custom Number Formats, I recommend simply selecting a standard format first, click on “custom” then and see how the standard format code looks like. If you repeat this step for a couple of standard formats, you will quickly understand how to use Custom Number Formatting.

Limitations

As mentioned above, Tableau’s Custom Number Formats are following Microsoft Excel’s standards. There are some limitations, though. The following Excel features are not available in Tableau:

  • No Color Coding

Excel allows you to color code the text font of a cell with custom formatting:
e.g. [Green] 0.00;[Red]-0.00;[Blue] 0 displays a positive number in green text font, a negative number in red and a zero in blue.

  • No Comparison Operators

[<50]"Low";[>100]"High";"Average" in Excel will display the defined texts depending on the values. Cells with a value lower than 50 will display “Low”, etc. Of course, you can combine the color coding (see above) and the comparison operators. None of them are available in Tableau.

  • No Repetition of Text

Excel allows you to fill the cell with any selected character and the number by using the asterisk (*), e.g. *_ 0.00 will show underscores left to the number. Tableau doesn’t provide this feature.

Especially the color coding is helpful sometimes and would be nice in Tableau,too. However, you can always use Tableau’s Calculated Fields to get what you want.

A Tableau Oddity: Is it a bug or a feature?

During the preparation of this post, I found a little oddity. It’s not a problem at all, but I thought you might be interested: If you are custom formatting a number and use the letter “C” (case insensitive), the number is displayed as a date including the time. I have no clue why.

Stay tuned.

Comments

39 responses to “Tableau Quick Tip #2 – Custom Number Formats”

  1. Acotgreave Avatar

    Great post – this is an area that can help people out greatly, but isn’t particularly well documented anywhere. Nice to see it blogged about.
    Andy

  2. talevizos@tableausoftware.com Avatar
    talevizos@tableausoftware.com

    Definitely a great post. Thanks! A few comments:
    ** “No color coding” – the mechanism is quite different from excel, but it is definitely in Tableau. As you state, you can use Tableau “calculated fields” to achieve any number of different and useful results. Tableau also has a built-in “Table Highlight” choice in the “Show Me” menu. Here is an example: http://public.tableausoftware.com/views/highlight_table/financials?:embed=yes&:toolbar=yes&:tabs=no
    ** “No comparison operators: – another area where it is hard to compare excel to Tableau. They both have extensive support for calculations and comparison operators are no exception. A Tableau calculated field can achieve the types of logic you mention above.
    ** Semi-related to your number formatting write up: Tableau has a knowledge base article on “date formatting” specific to Tableau Quick Filters. Over time, we have continued to make improvements in this area:
    http://www.tableausoftware.com/support/knowledge-base/supporteddateformatsinquickfilters
    Best Regards, -Ty Alevizos, Tableau Software

  3. Robert Avatar

    Ty,
    many thanks for your comment. It is great to see that some Tableau folks are still following my blog. Highly appreciated.
    I fully agree with all of your statements. Thanks for the links and the clarification. I didn’t want to sound off and the last thing I wanted to do is a comparison of Tableau and Excel.
    Yet, I haven’t seen the knowledge base article you linked to and the only documentation on Custom Formats in Tableau I found was in the Tableau manual, simply stating “This format can be specified by an Excel style number code”.
    That’s why I thought it might be a good idea to write about what is possible with Custom Number Formatting in Tableau and what is different than in Excel.
    As usual, there is more than one way to skin the cat. Calculated Fields or Highlight Tables are viable options to get what you want in Tableau.

  4. Richard Leeke Avatar

    Very useful, thank you Robert. I had discovered some of this by trial and error, but it’s really good to have it described. I also hadn’t seen the knowledgebase article that Ty pointed out.
    One other limitation which I would really like to see removed one day is that there is no support for formatting sub-second times. I use “hh:mm:ss.000” to display milliseconds all the time in Excel, but although Tableau honours the precision of the underlying field, there is no easy way to show it. I think I’m a bit of a lone voice on that one, though, I’ve never seen anyone else asking about it on the forums.

  5. Robert Avatar

    Richard,
    many thanks for your comment. I have to admit I never needed a number format showing milliseconds, neither in Excel nor in Tableau. But there will always be a first time, I am sure. Thus, I support your requirement. It shouldn’t be too hard for the Tableau team to put this into one of the next versions.
    By the way: your message was the 500th comment here. I know this is a very humble number compared to other blogs, but for me this is quite a milestone. I am very happy that it was you of all people who submitted number 500. Besides Giedre and Matt there is no one else who contributed more to Clearly and Simply than you did. A big time thank you very much for all the fantastic work you did here:

    Another Look at Site Catchment Analysis with Tableau 6 (Part 1)

    Another Look at Site Catchment Analysis with Tableau 6 (Part 2)

    Another Look at Site Catchment Analysis with Tableau 6 (Part 3)

  6. Mike Avatar
    Mike

    Can you show me a way to format numbers in such a way that a period is used for the thousand separator instead of a comma? When I try to do this, Tableau interprets the custom format as the number with three decimal places.
    Number (without formatting): 3,058
    Expected: 3.058
    Actual: 3058.000
    I would also like the end result to contain no decimal places. Is the custom format I described possible?

  7. Mike Avatar
    Mike

    The number in thousands format does not work in my case because numbers under 1,000 get converted into a decimal value. For example, the number 3 is converted to .3.

  8. Robert Avatar

    Mike,
    I do not know of a way to change the thousands and decimal separators using Custom Formatting, neither in Tableau nor in Excel.
    The separators are a regional setting of the Operating System. You can change those settings in the Control Panel (Regional and Language Options) as described in the Microsoft Knowledge Base here:
    http://support.microsoft.com/kb/307938

  9. Jay Avatar
    Jay

    Converting from millions to x.xM. Before: 2,345,456. After: 2.3M
    #,,.0M
    I did this just typing random combinations until it came out right. I thought Tableau was supposed to use Excel formatting.

  10. Michael Howard Avatar

    Mike
    The easiest way here would be to create a field as Value / 1000 and then show numbers to 3dp:
    6,789 becomes 6.789
    #,### to
    #.000
    This works great assuming you need no decimals and the numbers never get above 1m (then you’d have 1,234.567

  11. Robert Avatar

    Jay,
    thanks for your comment and sorry for the late reply.
    The easiest way of formatting numbers as millions is using Number (Custom) and selecting Millions (M) from the Units drop down. If you then click on Custom you see the format #,##0,,.00M, i.e. the one you found out.
    Having said that, you are right, there is a difference between the custom number formats in Excel and Tableau. Tableau expects to find the thousand separators (the commas) before the decimal point (#,##0,,.00). Excel accepts this too, but automatically transfers this custom format string to #,##0.00,, .
    See also my example for numbers in trillions in the article above (#,##0,,,,.00T).

  12. Nick Avatar
    Nick

    How do you get numbers to align when negatives are in ()? In excel, the format is:
    _(* #,##0_);_(* (#,##0)
    But that puts those literal characters around the number.

  13. Robert Avatar

    Nick,
    indeed, the Excel feature of inserting an empty space of the width of any given character by putting an underscore in front of this character in the custom format string is not available in Tableau.
    The Tableau manual is still saying

    “Custom: type in the format you want to use. This format can be specified by an Excel style number code.”

    That’s correct for the most common custom number format options of Excel, but there are some limitations in Tableau. See also the (non-exhaustive) section “Limitations” above.
    In a nutshell: I do not know of a way how to align positive and negative numbers in Tableau when the negative numbers are displayed in brackets.

  14. Azeey Avatar

    hi ,
    I am using custom formatting in tableau , I am getting error in date formatting. I have value 1.7 I am formatting it “dd:hh:mm:ss”, in excel it give me 00:04:00:00 (which is correct) and in tableau its giving me 30:04:00:00 (which is wrong). It take O days as max value 30 days kindly help me in this problem.
    Regards

  15. Azeey Avatar

    we can do this for expression but i dnt know how to write , but I can exoress my idea
    like
    if value <1 then sum (Value ) in hh:mm:ss format else sum (value) in dd:hh:mm:ss format.
    kindly reply

  16. Robert Avatar

    Azeey,
    the issue you are encountering isn’t the custom number formatting. It rather is Tableau’s date and time concept. Tableau’s “internal” calendar starts on December 31, 1899 (day 1). As you stated, a number like 0.25 in date & time format is 0 days 6 hours, 0 minutes. Thus, for Tableau, it is day zero of the calendar, i.e. December 30, 1899. That is why Tableau displays “30” as the dd-part of your custom formatting.
    Since Tableau relies on valid dates in the date / time dimensions, I do not know of a way to create a date with a day 0.
    The only solution I can think of is a Calculated Field creating a string in the format you want.
    The Calculated Field could look like this, for instance:
    IF DATETRUNC(‘day’, [Time Value]) = #12/30/1899# THEN
    “0:”+
    STR(DATEPART(‘hour’, [Time Value]))+”:”+
    STR(DATEPART(‘minute’, [Time Value]))+”:”+
    STR(DATEPART(‘second’, [Time Value]))
    ELSE
    STR(DATEPART(‘day’, DATEADD(‘day’,1,[Time Value])))+”:”
    +STR(DATEPART(‘hour’, [Time Value]))+”:”+
    STR(DATEPART(‘minute’, [Time Value]))+”:”
    +STR(DATEPART(‘second’, [Time Value]))
    END

  17. Padhu Avatar
    Padhu

    Hi,
    I’d like to know if there is a way I can hide the negative percentages in the worksheet.Am showing YOY calculations using table calculations and want to hide the negative percentages
    thanks

  18. Robert Avatar

    Padhu,
    the following custom number format hides the negative percentages:
    0.0%; ;

  19. Dora Avatar
    Dora

    I’ve been trying to figure out how to do a custom number format where the units are automatically determined – thousands (T), millions (M) or billions (B). Basically, I want it to behave exactly like the automatic number format, but with a dollar sign in front. The custom currency makes you pick a single unit type, and I want it to choose automatically. Any ideas?
    It would be helpful to know the formula for the automatic number format – I might be able to guess it from that.

  20. Robert Avatar

    Dora,
    Tableau automatically adjusts the units of numbers only on the axes labels and only if the number format of the measure is set to automatic.
    Mark labels (e.g. in charts or a text table or values shown in tooltips) are displayed according to the defined number formatting. The units of those labels are not changed by Tableau, even if their number format is set to automatic.
    Thus, I assume the automatic setting of the axes labels’ units is a Tableau internal procedure to optimize the appearance of the axes and has nothing to do with the defined number format.
    I do not know a way how to change this and I do not have a workaround. This doesn’t mean there is no way or workaround. I just don’t know one.

  21. James Avatar
    James

    The IF ELSEIF statement below solved my problem with regards to formatting numbers, percentages, and currency via a Tableau Calculated Field. . . the only issue left to figure out are commas between thousands (i.e. #,###). Any ideas anyone? I posted to the Tableau community board here: http://community.tableau.com/thread/154975
    IF ATTR([Ntype])= “0” THEN STR(sum([Data])) //Integer 0 decimal
    ELSEIF ATTR([Ntype])=”1″ THEN STR(ROUND(sum([Data]),2)) //Integer 2 decimal
    ELSEIF ATTR([Ntype])=”2″ THEN STR(ROUND(sum([Data]),4)) //Integer 4 decimal
    ELSEIF ATTR([Ntype])=”3″ THEN “$” + STR(sum([Data])) //Currency 0 decimal
    ELSEIF ATTR([Ntype])=”4″ THEN “$” + STR(ROUND(sum([Data]),2)) //Currency 2 decimals
    ELSEIF ATTR([Ntype])=”5″ THEN “$” + STR(ROUND(sum([Data]),4)) //Currency 4 decimals
    ELSEIF ATTR([Ntype])=”6″ THEN STR(sum([Data])*100)+”%” //Percentage 0 decimal
    ELSEIF ATTR([Ntype])=”7″ THEN STR(ROUND((sum([Data])*100),1))+”%” //Percentage 1 decimals
    ELSEIF ATTR([Ntype])=”8″ THEN STR(ROUND((sum([Data])*100),2))+”%” //Percentage 2 decimals
    ELSEIF ATTR([Ntype])=”9″ THEN STR(ROUND((sum([Data])*100),2))+”%” //Percentage 4 decimals
    END

  22. Robert Avatar

    James,
    this formula works for me, at least up to 999,999,999:
    IF INT(SUM([Data]) / 1000000) > 0 THEN
    STR(INT(SUM([Data]/1000000)))+”,”+
    MID(STR(SUM([Data])),LEN(STR(INT(SUM([Data]/1000000)))),3)+”,”+
    RIGHT(STR(SUM([Data])),3)
    ELSEIF INT(SUM([Data]) / 1000) > 0 THEN
    STR(INT(SUM([Data]/1000)))+”,”+RIGHT(STR(SUM([Data])),3)
    ELSE
    STR (SUM([Data]))
    END

  23. Tableau apprentice Avatar
    Tableau apprentice

    Hi Robert,
    Thanks for the very useful tips.
    I’m facing a custom formatting challenge.
    I’m using a parameter to switch between multiple metrics in a single calculated metric, and therefore the formatting has to be the same for all metrics.
    I want to show decimals for the smaller metrics (percentages and rations) and no decimals for the large integers (e.g total visiors).
    I’m currently using the #,##0.## format but integers such as 31500 are showing like 31,500. where the decimal separator at the end shows even when there are no decimals to display.
    Any simple workarounds you can think of?
    Thanks in advance!

  24. Robert Avatar

    Tableau apprentice,
    if you use the standard number format instead of your custom number format, decimals will only be displayed if there is something to display.
    If you want to define a threshold from where on decimals shall not be displayed, you could change your Calculated Field and round the numbers above the defined threshold to zero decimals. Something like:
    IF [Value] >= 10000 THEN
    ROUND([Value],0)
    ELSE
    [Value]
    END
    If you then use the standard number format, you should get what you want.

  25. Tableau apprentice Avatar
    Tableau apprentice

    Hi Robert,
    Thanks for the prompt response.
    The reason I was not using the standard number format initially was because it was capturing way too many decimals.
    I have now rounded the metrics to two decimals with Round(SUM(visitors),2) and it’s working well with standard number formatting.
    Thanks!

  26. Kristie Avatar
    Kristie

    Used $###,###,##0;$###,###,##0 to format all values as positives in table but still have grand total have the difference between revenues and expenditures.

  27. Robert Avatar

    Kristie,
    I am sorry, but I do not understand your question. Can you please describe your problem / requirement in more detail or post an example workbook somewhere?

  28. Rachel Avatar
    Rachel

    This advice partly helps with my problem, which is that my Excel data has a date column (15/06/2016) and a time column (01:00:00). Tableau does fine with the date column but the time column all becomes a date/time column (30/12/1899 01:00:00). I am guessing I either need to combine the date and time in excel before importing to tableau, or is there another trick? I am extremely new to Tableau and this is all very confusing!

  29. Robert Avatar

    Rachel,
    every time value in Excel has a date part, too. If you only enter the time in Excel, e.g. 01:00:00, and format the cell with the custom number format “mm/dd/yyyy hh:mm” (i.e. to show the date and the time, you will see this:
    1/0/1900 1:10:00 AM
    i.e. day zero in Excel’s calendar or the day before the first of January 1900.
    Same thing in Tableau, i.e. in Tableau a time field always has a date part, too. In your case, all times belong to day zero in Tableau’s calendar. If you want to combine the date and time field, you do not have to do this in Excel. You can also do this in Tableau by creating a Calculated Field which is simply adding the time to the date.
    Let’s say [myDate] is the date dimension and [myTime] the time dimension in your Excel data. Create a Calculated Field in Tableau, name it e.g. DateAndTime and enter this calculation:
    [myDate]+[myTime]
    This should do the trick.

  30. Keith Avatar
    Keith

    Create a calculated field for ABS([Sales]) for the values in the table. Then create a separate page for the Grand Total and combine them in a Dashboard.

  31. Russell Avatar
    Russell

    I have a data that has time listed in the hh:mm format, when I sum the total if the amount exceeds 24 hours Tableau will only show the amount over 24 hours. Example sum of time is 26:30 Tableau shows it as 2:30.
    How do I get the sum to show 24 hours, I tried using [h]:mm from Excel but would show that as “:12”.

  32. Robert Avatar

    Russell,
    Jonathan Drummey wrote an excellent article about this topic over at his blog Drawing with numbers:

    Formatting time durations

  33. Nagaraju Avatar
    Nagaraju

    for Indian currency format try this
    IIF(LEN(STR([CAL1]))<=3 ,STR([CAL1]) ,IIF(LEN(STR([CAL1]))=4 ,LEFT(STR([CAL1]),1)+','+RIGHT(STR([CAL1]),3) ,IIF(LEN(STR([CAL1]))=5 ,LEFT(STR([CAL1]),2)+','+RIGHT(STR([CAL1]),3) ,IIF(LEN(STR([CAL1]))=6 ,LEFT(STR([CAL1]),1)+','+mid(STR([CAL1]),2,2)+','+RIGHT(STR([CAL1]),3) ,IIF(LEN(STR([CAL1]))=7 ,LEFT(STR([CAL1]),2)+','+mid(STR([CAL1]),3,2)+','+RIGHT(STR([CAL1]),3) ,iif(LEN(STR([CAL1]))=8 ,LEFT(STR([CAL1]),1)+','+mid(STR([CAL1]),3,2)+','+mid(STR([CAL1]),6,2)+','+RIGHT(STR([CAL1]),3) ,IIF(LEN(STR([CAL1]))=9 ,LEFT(STR([CAL1]),2)+','+mid(STR([CAL1]),3,2)+','+mid(STR([CAL1]),5,2)+','+RIGHT(STR([CAL1]),3) ,IIF(LEN(STR([CAL1]))=10 ,LEFT(STR([CAL1]),3)+','+mid(STR([CAL1]),4,2)+','+mid(STR([CAL1]),6,2)+','+RIGHT(STR([CAL1]),3) ,IIF(LEN(STR([CAL1]))=11 ,LEFT(STR([CAL1]),1)+','+mid(STR([CAL1]),2,3)+','+mid(STR([CAL1]),5,2)+','+mid(STR([CAL1]),7,2)+','+RIGHT(STR([CAL1]),3) ,STR([CAL1]) ))))))))) // vailed for upto 1000 Cores

  34. Tanapan Avatar
    Tanapan

    I can’t change the format time in tableau the way I want. Which will allow my hours to exceed 24 hours.
    Here’s what I do. Default properties/Number format /Custom-/[h]:mm:ss
    Is there a way to help?

  35. Robert Avatar

    Tanapan,
    Jonathan Drummey wrote a fantastic blog post including a solution for your problem:

    Formatting Time Durations in Tableau

  36. Sunil Kambrath Avatar
    Sunil Kambrath

    This is a great post. How do we show 0.0257 as 2.57?

  37. Robert Avatar

    Sunil,
    easiest way would be to format the number as percentage, but I assume you want to get rid of the percentage sign, right? If so, I do not see a way to do this with custom formatting. You would have to create a Calculated Field which multiplies the value by 100.

  38. Maria Avatar
    Maria

    Hi Robert,
    Thank you for the helpful post. Is there any way to show to display fractions in Tableau by using custom number formatting? In Excel it would be something like “# ??/???”, but question marks seem being not supported in Tableau custom number formatting.

  39. Robert Avatar

    Maria,
    I do not know of a way to display numbers as fractions in Tableau. The only way I see would be to create a Calculated Field dividing the decimal number into the integer, the nominator and the denominator and concatenating those parts separated by the fraction slash.

Leave a Reply

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