4 Replies Latest reply on May 18, 2017 3:42 AM by Simon Runc

# Convert data into percent format without string data type

Hi,

I have my data value as 0.20.  I would like to convert into percent format as 20%.  Does anyone know how to convert it in calculated field and not to make it into a string data type as I need to calculate totals further.

I use the following formula now with parameter:

IF [Choose value]='Absolute' THEN [Number of Tasks]

ELSEIF [Choose value]='Percent' THEN [% of Total]

END

Karolina

• ###### 1. Re: Convert data into percent format without string data type

Hi Karolina,

So the lack of dynamic formatting in Tableau (for measure selectors) is a bit of a pain...you may want to vote this idea up!

however there is a workaround....

In the attached I've got a measure selector which returns Sales (£) or Share of Sales (%). I set up 2 calcs

[Select Measure: Sales]

IF [Select Measure] = 1 THEN SUM([Sales]) END

[Select Measure: %age Share]

IF [Select Measure] = 2 THEN SUM([Sales]) / TOTAL(SUM([Sales])) END

as there is no ELSE statement then when one is selected the other returns NULL (and Tableau doesn't, well can't - no one can!, plot nulls!). So I set up the formatting for one as £ and the other as %age...and bring them both into the Label, and set it up as per the below

and voila we have dynamic formatting!

Hope that does the trick and makes sense.

3 of 3 people found this helpful
• ###### 2. Re: Convert data into percent format without string data type

That's really useful, Simon Runc.

• ###### 3. Re: Convert data into percent format without string data type

Simon! Thank you so much! It is really great!!!

• ###### 4. Re: Convert data into percent format without string data type

Cool, glad it did the trick!

This is the same (basic) technique to do things like applying colours and formatting in ToolTips...eg. make one calc: IF [var on Sales] >= 0 THEN [var on Sales] END and then another calc: IF [var on Sales] < 0 THEN [var on Sales] END...put them side-by-side (in the tooltip), make one green and one red, and when someone hovers over, they'll get a Red if its negative, and Green if it's positive!

1 of 1 people found this helpful