13 Replies Latest reply on Jun 12, 2018 7:06 AM by Ruben Arias

# % Parameter calculation

Hello Tableau'ers.  I am trying to create the following % parameters under gross profit % column for my report:

>10%

<10%-0%

<0%

ALL %

How do I write the calculated field correctly, in order to produce the parameters outlined?  Below is what I have for my \$ parameter, which is working correctly.  I attempted to amend it with the new fields but no luck.

IF [selection %] = 'All Positive Values' THEN

(IF [Calc : % DIff] > 0 THEN [Calc : % DIff] END)

ELSEIF [selection %] = 'All Negative Values' THEN

(IF [Calc : % DIff] < 0 THEN [Calc : % DIff] END)

ELSE

([Calc : % DIff])

END

Thanks!!

• ###### 1. Re: % Parameter calculation

Hi Ruben,

The if clause needs to match up with what you have with the parameter.

You can change the parameter to only have values of

All Positive Values and All Negative Values:

Or if you want the existing parameter to work with your calculation, we can update the calculated field:

IF [selection %] = '>10%' THEN

(IF [Calc : % DIff] > 0.1 THEN [Calc : % DIff] END)

ELSEIF [selection %] = '10%-0%' THEN

(IF [Calc : % DIff] >=0 and [Calc : % DIff] <10 THEN [Calc : % DIff] END)

ELSEIF [selection %] = '<0%' THEN

(IF [Calc : % DIff] < 0 THEN [Calc : % DIff] END)

ELSE

([Calc : % DIff])

END

Thanks,

Mavis

• ###### 2. Re: % Parameter calculation

Hi

I wont comment on the calculation because I can't see the data or your workbook

but you are creating a STRING parameter - the values are text not numeric values

if you want to test specific text in you if statements that text (literal) needs to be the value in you parameter statement

see below

Jim

If this posts assists in resolving the question, please mark it helpful or as the 'correct answer' if it resolves the question. This will help other users find the same answer/resolution.  Thank you.

• ###### 3. Re: % Parameter calculation

Edit: The calculation should be

IF [selection %] = '>10%' THEN

(IF [Calc : % DIff] > 0.1 THEN [Calc : % DIff] END)

ELSEIF [selection %] = '10%-0%' THEN

(IF [Calc : % DIff] >=0 and [Calc : % DIff] <0.1 THEN [Calc : % DIff] END)

ELSEIF [selection %] = '<0%' THEN

(IF [Calc : % DIff] < 0 THEN [Calc : % DIff] END)

ELSE

([Calc : % DIff])

END

Thanks,

Mavis

1 of 1 people found this helpful
• ###### 4. Re: % Parameter calculation

Hi Mavis, thank you!!!

I tried all four parameter selections, but the 10-0% is not filtering correctly.  Its showing values above 10%.  I tried to amend the calculated field, but no luck.

Any ideas?

Thanks!!!

• ###### 5. Re: % Parameter calculation

OK, thanks, let me try it now

• ###### 6. Re: % Parameter calculation

Thanks Mavis, that did the trick!!!

Marking it as correct answer now.

• ###### 7. Re: % Parameter calculation

Glad to have helped Ruben, thanks for marking it as correct

• ###### 8. Re: % Parameter calculation

Mavis, last question.  When I drag the calc field to filter, and then under special I have to choose non-null values.  If I choose all values, then my parameters dont work.  But, I would like to keep all values, since my grand totals are less at the very bottom if I do not.  Anyway to include all values under special, and the parameters still work?

• ###### 9. Re: % Parameter calculation

For example, if I change % filter from all values to non-null, the grand total is less.

• ###### 10. Re: % Parameter calculation

Hi Ruben,

In that case change it to:

IF  [Calc : % DIff] = 'All Values' then 'True'

ELSEIF

[selection %] = '>10%' THEN

(IF [Calc : % DIff] > 0.1 THEN 'True' END)

ELSEIF [selection %] = '10%-0%' THEN

(IF [Calc : % DIff] >=0 and [Calc : % DIff] <0.1 THEN 'True' END)

ELSEIF [selection %] = '<0%' THEN

(IF [Calc : % DIff] < 0 THEN 'True' END)

ELSE

'True'

END

Then set the filter to 'True' and see if this works.

Thanks,

Mavis

• ###### 11. Re: % Parameter calculation

Thank you Mavis, I am getting a calc error stating cant compare float and string values.

• ###### 12. Re: % Parameter calculation

Hi Ruben,

Sorry should be this:

IF  [selection %] = 'All Values' then 'True'

ELSEIF

[selection %] = '>10%' THEN

(IF [Calc : % DIff] > 0.1 THEN 'True' END)

ELSEIF [selection %] = '10%-0%' THEN

(IF [Calc : % DIff] >=0 and [Calc : % DIff] <0.1 THEN 'True' END)

ELSEIF [selection %] = '<0%' THEN

(IF [Calc : % DIff] < 0 THEN 'True' END)

ELSE

'True'

END

Thanks,

Mavis

1 of 1 people found this helpful
• ###### 13. Re: % Parameter calculation

TY again Mavis, that did the trick.  Much appreciated!!!

Ruben