Tableau Software is a surprisingly versatile tool. Not only does it provide a wide spectrum of data visualisation options but it is also a powerful reporting aid.
A rather interesting use-case I have recently encountered at work involves selectively formatting numbers present in a single datatable in Tableau.
For example, the following table contains dummy values for the Vaccination Rates of 3 randomly selected countries:
While Tableau enables the user to Format these numbers from the side panel, in order to selectively display values with a custom no. of decimal place (#.#, #.## etc.) or as custom text (E.g. for values less than 65, it shall be displayed as "≤65" instead) within the same table, the following formulas in the respective calculated fields may be considered for such instances instead.
Calculated Field: [Position of Decimal (.)]
FIND( STR([Vaccination Rates]), '.' )
Calculated Fields for Displaying a custom no. of decimal places
i) [Display=1 Decimal Place]
LEFT(
STR([Vaccination Rates]),
[Position Of Decimal (.)]+1
)
Note: The bolded number above represents no. of decimal places desired (a.k.a. the no. of digits to display after the "." symbol)
ii) [Display=2 Decimal Places]
LEFT(
STR([Vaccination Rates]),
[Position Of Decimal (.)]+2
)
Note: The bolded number above represents no. of decimal places desired (a.k.a. the no. of digits to display after the "." symbol)
Final Display of Numbers
Main Assumptions:
- 2 Decimal Places are displayed for values ≥75
- Only 1 Decimal Place is displayed for values > 65 but less than 75
- Values ≤65 are summarised as ‘≤65%’
IF [Vaccination Rates] >= 75 THEN [Display=2 Decimal Places]+'%'
ELSEIF [Vaccination Rates] > 65 THEN [Display=1 Decimal Place]+'%'
ELSE '≤65%' END
Altogether…
And there you have it! Many thanks for persisting to the end of this article! ❤ Hope you have found this guide useful and feel free to follow me on Medium if you would like more GIS, Data Analytics (Tableau-inclusive) & Web application-related content. Would really appreciate it – 😀
For more Tableau tips and tricks, feel free to check out the below posts:
How to Plot a Custom Map Image on Tableau Dashboard in just 3 Easy Steps – No calculations…
Leverage on D3.js v4 to build a Network Graph for Tableau with ease
5 Lesser Known Tableau Tips, Tricks & Hacks. With Use-Case + Demo.
Superscript and Subscript in Tableau – Why and How you can implement it
Underrated Combined Functionalities of Tableau – Point, LineString & Polygon Mapping