3 Replies Latest reply on Jun 12, 2017 10:20 AM by Pax Gray

# Calculated Field If Function

Sorry for the basic question. I'm new to tableau and need help formatting a function. What I would like is a percentage of the total within a dimension. I want it to go something like this:

IF the Result is "positive", then calculate positive divided by total. Can Someone help me format this with the order and punctuation of the function?

Thank you much

• ###### 1. Re: Calculated Field If Function

EX:

If [Profit] > 0 Then [Profit]/[Total]

END

• ###### 2. Re: Calculated Field If Function

Hi Pax Gray,

You cannot do the percent of total for a Dimension field. It will be possible only on the measures.

Syntax for calculating the percent of Total: Sum(Measure)/total(sum(measure))

Example:

If you have a dimension like Product Name and the measure say Sales. If you would like to calculate the Percent of total for the Product Apple then you can write your calculation like this.

If ATTR( [Product Name]) = 'Apple' then

Sum(Sales)/total(sum(sales)) End

Please let us know, in case you have any further questions.

Thanks & Regards