7 Replies Latest reply on Sep 7, 2012 9:14 AM by Shawn Wallwork

# Use Calculated Fields as functions

Hi,

is it possible to use Calculated Fields as functions?

For example, I need to implement this function

"

If [x]<0 then

param=NULL

else

param=[x]

end

if [y]>0 then

param=param+[y]

end

return param

"

In Tableau I have to create intermediate calculated field

temp1=

If [x]<0 then

param=NULL

else

param=[x]

end

Value=

if [y]>0 then

[temp1]+[y]

else

[temp1]

end

• ###### 1. Re: Use Calculated Fields as functions

Sergey, when [x]<0 do the two equation return NULL or [x]?

--Shawn

• ###### 2. Re: Use Calculated Fields as functions

It should return NULL.

• ###### 3. Re: Use Calculated Fields as functions

Sergey,

I think you're looking for this:

IF [X]<0 THEN NULL ELSE (IF [Y]>0 THEN [X]+[Y] ELSE [X] END)  END

See attached file. Let me know if it isn't what you're looking for. Specifically what you want to happen when (Y)<=0.

--Shawn

1 of 1 people found this helpful
• ###### 4. Re: Use Calculated Fields as functions

Ok. Thank you, I'll use nested conditions.

So there is no scripting engine like VBA in Tableu at this point, hope they will implement it some day.

• ###### 5. Re: Use Calculated Fields as functions

Couple of notes:

Hope this helps.

--Shawn

• ###### 6. Re: Use Calculated Fields as functions

There's an idea for user defined functions here: http://community.tableau.com/ideas/1130

• ###### 7. Re: Use Calculated Fields as functions

Here's the link Jonathan was trying to point to: User Defined Functions

--Shawn