Best practice for using arrays or ranges of data in Alteryx formulas
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Hi community,
Have been working through a methodology that refers to a number of data ranges / conditions or arrays and I've been working through the best way to deal with it.
For example, I've been converting the following table into a workflow and wanted to get some thoughts on if this is the best way to achieve this. My method works but it's a little cumbersome and doesn't scale very well so I thought I'd ask the brains trust.
Value | Description | Definition |
0 | In scope to access the course | SCOPE = 1 and (LEVEL in (DEG, OUG, PUGD, PUGO) or AWARDLEVEL in (DEG, OUG, PUGD, PUGO)) |
1 | Not included and unable to access | Otherwise |
I've simply created a formula tool and added all the calculations manually one after the other to the formula tool using AND, OR and brackets to denote the calculation:
[SCOPE] = 1 AND
([LEVEL]="DEG" OR [LEVEL]="OUG" OR [LEVEL]="PUGD" OR [LEVEL]="PUGO" OR [AWARDLEVEL]="DEG" OR [AWARDLEVEL]="OUG" OR [AWARDLEVEL]="PUGD" OR [AWARDLEVEL]="PUGO")
Is there a more elegant way to put this together, or more robust / reusable way?
In the past, I've often used a text input tool and done a join but that only works if there's one list of criteria not when you're testing against two sets of criteria, as is the case above where you're checking against LEVEL and AWARDLEVEL fields.
Solved! Go to Solution.
- Labels:
- Common Use Cases
- Datasets
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Hi @w_chivers
Something like this would simplify the formula:
[SCOPE] = 1 AND ([LEVEL] in ("DEG","OUG","PUGD","PUGO") OR [AWARDLEVEL] in ("DEG","OUG","PUGD","PUGO"))
If the list of values is expected to change, you could use a summarize tool to concatenate each list and pass them into a macro that will update the filter tool dynamically.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Hello @w_chivers. I made a dynamic selection using a batch macro. There may be an easier way to do it, but you're able to feed in your terms (i.e., both the "LEFT" terms and the "RIGHT" terms) into a Python tool, which creates the formatted terms for use in the batch macro. I made it so that you can send a different number of terms to the left and right sections as well. I also added two outputs, so you can see which ones are in scope and which ones are out of scope.
I attached the workflow and macro. Is this what you're looking for?
Setup
Workflow
Batch Macro
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Thank you both for your replies and different approaches. Very helpful.
