Community Spring Cleaning week is here! Join your fellow Maveryx in digging through your old posts and marking comments on them as solved. Learn more here!

Alteryx Designer Desktop Discussions

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

Best practice for using arrays or ranges of data in Alteryx formulas

w_chivers
7 - Meteor

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.

 

ValueDescriptionDefinition
0In scope to access the courseSCOPE = 1 and (LEVEL in (DEG, OUG, PUGD, PUGO) or AWARDLEVEL in (DEG, OUG, PUGD, PUGO))
1Not included and unable to accessOtherwise

 

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.

 

best practice for array or ranges.png

3 REPLIES 3
Luke_C
17 - Castor

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.

 

acarter881
12 - Quasar

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

Spoiler
acarter881_2-1666112767294.png

 

Workflow

Spoiler
acarter881_4-1666113581542.png

 


 

Batch Macro

Spoiler
acarter881_3-1666113541773.png

 

 

w_chivers
7 - Meteor

Thank you both for your replies and different approaches. Very helpful. 

Labels