4 Replies Latest reply on Nov 4, 2015 10:30 PM by Karthick J

# Calculated field

IF Dimension B =0 then "NONE" else Dimension A / Dimension B (A/B)%

Example:

If  Dimension A = 3

Dimension B = 0

then display as "None"

else

suppose Dimension A =3 and Dimension B= 2  then display as "3/2 (1.5%)"

• ###### 1. Re: Calculated field

Firstly, 3/2 doesn't equal 1.5% but I'll assume that you know that ....

Secondly, is A & B really dimensions, or are they measures ?

Finally, if A & B are measures, then I did this :

```if [B] = 0 then "None" else str([A]/[B]) + "%" end
```
• ###### 2. Re: Calculated field

Hi,

1) Create a calculated field like below,

if [B]<>0 then [A]/[B] end

2) Right click on the above calculated field in the Measures window then click on "Change properties" then click on
Number Format, then select "Percentage"............

Nulls Handling - String, Date, Numerical Data types

Best Regards

Tableau Kumar

• ###### 3. Re: Calculated field

Hey Karthick,

As Chris pointed out, there are a couple of issues with the semantics of your question, but I think the crux of your issue is the formatting of the result, right? If so, give this one a try:

IF [Dimension B] = 0 THEN "None"

ELSE STR([DIMENSION A]) + "/" + STR([DIMENSION B]) + " (" + STR([DIMENSION A]/[DIMENSION B]) + "%)"

END

You may also need to utilize a ROUND() function on the two dimensions divided to get the single decimal, but other than that I think that's what you're looking for.

Best,

InterWorks

• ###### 4. Re: Calculated field

Hi Jimmy,

Thanks lot.

Kumar  / Chris McClellan

Regards

Karthick