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

Alteryx Designer Desktop Discussions

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

Adding a UDF to a workflow

Paul_s_Moody
8 - Asteroid

Hi,

Looking through the online help, and browing the community, I suspect the answer is "no", but is it possible to add a simple UDF to a workflow that all users of the workflow would have access to?

This is akin to adding a simple VBA function in an Excel spreadsheet.

 

The online help suggests that it is possible to build something in XML, but would have to be "saved" to each users local machine individually.

My company structure uses remote VDI machines so staff don't have access to a local "C:\" drive to carry this our.

 

In my workflow, I'm having to adjust the persons retirement dates depending whether the birthday was a leap year, and/or the retirement date(s) is also a leap year and depending on their gender.

 

I've worked around the problem by adding 2 additional columns that give a boolean response to the "is the input date a leap year", and then referencing the new columns before deselecting them in the next tool.

 

Paul_s_Moody_0-1679051409748.png

 

As I've had to use the same core code, albeit referending different columns, to generate 2 new columns, this seems a bit of unnecessary duplication.

Similar comments to the "if male add 65 years to a date, or 60 if female". If this were in VBA I'd probably add this simple code into another UDF to tidy things up!

 

Thanks in advance,

4 REPLIES 4
Clifford_Coon
11 - Bolide

Hi Paul,

 

You should be able to use a standard macro here:

Something like the following 2 images:

1- Workflow Example

Leap_Year.jpg

2- Macro

IsLeapYear.jpg

Attaching a .xyzp file.

 

Good Luck!

danilang
19 - Altair
19 - Altair

Hi @Paul_s_Moody 

 

Once this macro is built, add it to shared directory that all users have access to.  Then get the users to configure that path in the Macros tab of User Settings.

 

danilang_0-1679148560334.png

 

Any macro placed in this path will then become available to all users.  My image is taken from my home computer, so it shows the drive letter, but you can use a UNC path here as well.   

 

Dan

 

apathetichell
19 - Altair

This kind of makes my head hurt - I feel like you could do this entire thing in one formula tool and it would be much faster and cleaner. You can use the %j to see the number of days in a year. You could do something like:

 

you can test if something is a leap year with datetimeformat(todate(tostring(datetimeyear([SPD]))+"-12-31"),"%j")="366"

 

you can test if you are looking for 2/28 or 2/29 by see if datetimeadd(todate(tostring(datetimeyear([SPD]))+"-01-01"),59,"DAYS") is 2/29 (like it is in a leap year) or 3/1. if this is 3/1 you subtract a day. But this should be fairly straight forward.

Paul_s_Moody
8 - Asteroid

Thanks for all of your help!

Lots of ideas to try in my workflow.

Labels
Top Solution Authors