Advent of Code is back! Unwrap daily challenges to sharpen your Alteryx skills and earn badges along the way! Learn more now.

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

Is there a way to make a user-defined functions that we can use in formula tool?

hlee36
8 - Asteroid

When I use a formula in Excel and don't have an exact formula to use or when it is burdensome to make a formula with bunch of functions many times, I go to VBA and make a user-defined functions.

 

It is really time-consuming to make a same formula over and over. Is there a way to make a user-defined function? 

 

For example, if [field1] > [field2] then [field1]*[field2] elseif [field1] = [field2] then -1 else [field1]/[field2]

 

I want to define the above expression as a function, multiplyOrDivide([field1], [field2]). I have way too many columns to copy and paste the formula and change each argument in the parameters. 

 

 

 

 

4 REPLIES 4
Luke_C
17 - Castor
17 - Castor

Hi @hlee36 

 

There is a way to save expressions, maybe this helps? https://help.alteryx.com/10.6/SavedExpressions.htm

Luke_C_0-1686853773354.png

 

 

hlee36
8 - Asteroid

Yeah, that's what I've been using. When I load saved expression,

 

if [field1] > [field2] then [field1]*[field2] elseif [field1] = [field2] then -1 else [field1]/[field2]

 

Now, I have to change each argument 8 times in the above expression when I need to change the fields. 

 

I was wondering if I can define the above expression as my own function, multiplyOrDivide([field1], [field2]) so I only have to change 2 arguments whenever I use the expression each time. This, I could do in Excel when I go to development tool where the VBA is. Not only it reduces the burden of changing columns, but it is easy to read and easy to maintain.

 

If there is no way to do in Alteryx, I think this is the part where Alteryx is inferior to Excel. 

I appreciate your input, though.

Luke_C
17 - Castor
17 - Castor
hlee36
8 - Asteroid

Thanks, this is what I have been looking for.

 

I'm really glad this exists in Alteryx.

 

(Only found out my company blocked the directory of the folder for added function. lol. I will talk to my company to unblock it.)

Labels