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.
SOLVED

Dynamic solution to filter data on basis of multiple conditions and get multiple outputs

Radhika
6 - Meteoroid

Hi All,

Can anyone help me with this scenario?

I have one input as a database, below is its format. I have some filter conditions to get data.

I need to create multiple flows in one canvas based on filter conditions and get multiple outputs.

Each condition can vary on different columns of input with 'and' and 'or' conditions and in the output, I need 3 columns - Eid (from input ), Category, Code (created in the canvas based on conditions defined),

Required: I need to create an optimized alteryx solution where I can have all the columns of the input and every time a new condition is given, I just need to add 'AND' and 'OR' conditions to those particular columns mentioned in the condition and generates a new output of 3 columns (Eid, Category, Code)  in the same canvas in which Category and code are generated during the flow as per the condition. Hardcode values will be given for Category and Code in every defined condition. 

 

Example : 

Input sample

EidProcess_dateDeptAssigned_teamLocationSal_currencyBase_locationUnitManager_NameDays
120-07-2022AAAZCADZZavhjAB1
221-07-2022BBBYINRYYyahjVBF2
322-07-2022BCCXJPYTTavhHG3
423-07-2022DDDWUSDWWkgsSJ4
5 24-07-2022EEEVCADVVnjhAJ5

 

Let's say I have condition 1 for 1st flow -

Dept =A and sal= CAD then category = 'def' and code ='11'

Output - Output should be

EidCategorycode
1def11

 

Condition 2 :

Dept=B and (assigned_team = bb or cc) and (unit = YY or TT) then category = 'GHI' and code ='22'

the output should be ;

EidCategorycode
2GHI22
3GHI22

 

Condition may use any string functions on any column.

Here I have given two conditions only but there'll be around 100 so I need an optimised and automated data driven solution for this so that every time a condition is given, I have to just add 'AND' and 'OR' conditions to the particular columns and less of manual work.

If anyone can help, Thanks in advance.

14 REPLIES 14
FilipR
11 - Bolide

 

EDIT: I didn't read the part about 100 conditions before answering, sorry. :D

 

Radhika
6 - Meteoroid

Thanks FilipR for solution but yes, I need a dynamic solution to this where I will have to just add logic for particular columns whenever a new condition is given

FilipR
11 - Bolide

OK, I have something for you after all. 😀

 

You have to compose your list of Filter conditions and the results in a Text Input like this:

FilipR_0-1662565186500.png

 

Then you connect your input together with the list to the macro I created for you:

 

FilipR_1-1662565255769.png

 

FilipR_2-1662565264672.png

 

The results:

 

FilipR_3-1662565325793.png

 

 

Radhika
6 - Meteoroid

Hi FilipR, Thanks a lot for the solution.

I am implementing the same on the real data its not giving output though te records are flowing accordingly but not getting output after macro and everything is fine until macro's output.

Is there anything which I need to know, Also just to understand what does 1=1 represents in the filter?

FilipR
11 - Bolide

@Radhika, if you are not getting any output, then most likely the conditions you put in the indicated field are invalid. Please check your syntaxes and test if they work if you put them in a regular Filter tool.

 

The 1=1 is just a placeholder. The macro replaces it with whatever you put in the Conditions field.

Radhika
6 - Meteoroid

@FilipR   is there any data-specific condition that you have applied here in macro (either in filter or formula) because, in macro, data is not getting joined as per my data because cond=0 and recordid=1, and there is no output then?

FilipR
11 - Bolide

@Radhika please give me an example where it does not work for you so I could test for myself.

 

The macro is plug and play. You don't change anything inside of it. It will return rows if they meet the conditions you feed into it. It will not return a row if it does not meet any conditions.

Radhika
6 - Meteoroid

Done. Thanks for the help.

FilipR
11 - Bolide

@Radhika I am not sure where do you have problems then. The macro goes row by row. Having a column with a unique ID is not required. Only the conditions you put in the Text Input have to make sense and need to follow the right syntax.

 

I provided you with a working example based on the data and conditions you provided.

 

Please mark my post as a solution.

Labels
Top Solution Authors