We are celebrating the 10-year anniversary of the Alteryx Community! Learn more and join in on the fun here.
Start Free Trial

Alteryx Designer Desktop Discussions

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

Dynamic Filter with dynamic column names and filter values

kwilda
6 - Meteoroid
 

I would like to read in and append a filter string, [RunTimeFilter], to filter to a workflow. The [RunTimeFilter] would be unique for each input file as the column names would change file over file.

 

Example:
Col1 = 1 and (Col2 = "X" or Col2 = 'Y') for File A

ColA = 1 and (ColZ = "A" or ColB = 'Y') for File B

 


When manually added as a custom filter, this works, but when attempting o pass it in as a column variable, I can't figure out the syntax.

 

I attempted to use the dynamic filter batch macro, but I'm using the same flawed logic in a filter tool.  

 

Any help or guidance is greatly appreciated as I didnt find a solution in other posts

 

Thanks in advance

 

2 REPLIES 2
YasirShafique123
5 - Atom

To pass a dynamic [RunTimeFilter] as a variable in a filter tool in Alteryx:

  1. Use the Formula Tool: Create a string column (e.g., FilterString) containing your filter logic.
    Example:

    arduino
    IF File = "A" THEN "Col1 = 1 AND (Col2 = 'X' OR Col2 = 'Y')" ELSEIF File = "B" THEN "ColA = 1 AND (ColZ = 'A' OR ColB = 'Y')" ENDIF
  2. Dynamic Filter Tool: Use the "Dynamic or Batch Filter" and point the filter expression to the FilterString column.

  3. Use a Batch Macro: If multiple files have different filters, create a batch macro where [RunTimeFilter] gets passed as a control parameter to update the filter logic dynamically.

This avoids syntax issues by treating the filter as a string input.

apathetichell
20 - Arcturus

use dynamic rename to change the name of the column you are filtering for in the batch macro. keep the filter field name static. so [My field to filter]=[value] in your filter stays static. the field with the name changing is variable and controlled in dynamic rename. use a second action tool to a second dynamic rename to reset to the original name after the filter.

 

syntax something like if [_CurrentField_]='mydummyNAME' then 'MyVariableField' else [_CurrentField_] endif

 

action tool changes specific field - 'mydummyNAME' 

 

filter [MyVariableField]=[variablevalue]

 

dynamic rename 2:

 

if [_CurrentField_]='myVariableField' then 'mydummyNAME' else [_CurrentField_] endif

 

action tool 2 has the same config but runs in reverse.

 

f

Labels
Top Solution Authors