Leveraging user-defined workflow constants in Alteryx Designer
by Nathan Purvis
Background
If you find yourself using the same reference value in multiple places throughout a workflow, or are wishing you could make a single change to a value that is reflected across several instances, then you may want to make use of workflow constants! These are global variables that we can define in the Workflow tab and use again and again within our process. Let’s dive straight into a couple of examples!
Company inception date:
A business can only be created/founded once, and so if we ever had a scenario where we wanted to measure the time between this date and another event, we’d need to keep typing in the inception date. Well, you guessed it, not if we use a workflow constant! If we navigate to the ‘Workflow’ tab of our general workflow configuration (which you can get to by hitting any white space on the canvas), you’ll see a ‘Constants’ section, with a ‘+’ button:
If we click this, Alteryx will then create a ‘User’ constant and we can then define a name and value for it as shown here:
Now, let’s say we want to calculate how long from inception it took to hire certain employees, we can then reference this value in our expression editor. If we place a Formula tool on the canvas and go to our ‘Columns and Constants’ menu, we’ll find our ‘Inception Date’ constant here:
This means that we can now just reference the value whenever we need to, rather than having to constantly re-type this in each expression. Here we’re just going to print the date itself and also just use it to calculate the time between the company starting and hiring people:
The great thing about these user defined constants is that, if we need to change them, they are automatically reflected everywhere. For this scenario, let's imagine whoever created the workflow accidentally used the incorrect inception date. We can now just go back into the ‘Workflow’ tab and edit this:
When we re-run the workflow, the new value will now be used:
Starting salaries for said business
Now, the beady-eyed amongst you will have noticed that, when adding a new user constant, there is an extra tick box. This is to indicate that the value is numeric, so let’s take a look at an example where everyone at the company begins on the same wage and we want to measure how much extra they’re earning now. First, we’ll set our starting salary and ensure the ‘Is Numeric’ box is checked:
Again, just for the sake of demonstration, we’ll print out the value of the constant initially, then show it within an expression:
Once more, if we change the value in our ‘Workflow’ configuration tab, that value then pulls through wherever the constant is referenced:
Hopefully this short guide and the examples shown above help to provide you with an insight into the value of workflow constants and how they can be used to save time and effort when developing Alteryx workflows. Please feel free to reach out if you have any further questions or feedback!