Start Free Trial

Alteryx Designer Desktop Discussions

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

Delete rows based on specific conditions

barkat
6 - Meteoroid

I have the below problem, if there is a row with action 'NEW' and directly below this row with the same id there is a 'CANCEL' .Then we need to remove  both rows ( new and cancel) .Can anyone hep suggest a logic in Alteryx for this? 

 

input data: 

 

AmountACTIONID
400000NEW72
500000NEW12
500000CANCEL12
0CORRECTION12
20000NEW89
20000CANCEL89
10000NEW11
90000NEW20
12000NEW23
12000CANCEL23

 

 

output of what I want to achieve:

 

AmountACTIONID
400000NEW72
0CORRECTION12
10000NEW11
90000NEW20
8 REPLIES 8
Emil_Kos
17 - Castor
17 - Castor

Hi @barkat,

 

I have prepared a workflow using multi-row formula tool:

 

Emil_Kos_0-1618573254545.png


I am comparing if the current row and the previous row meet specific requirements. After that, I am checking if the current row and the next row meet another need.

When it is done, I just need to filter out the data.

 

mbarone
16 - Nebula
16 - Nebula

Probably several ways to do this, but here's what I would do, as long as it will always be the cancel row beneath the row you want to delete:

 

Multi-row Formula to set a new field to 1 if it's "CANCEL" and the ID before it matches it's ID.

Another Multi-row Formula to set yet another new field to 1 if the row below it is 1.
Then Filter out all the 1s:

2021-04-16 07_45_19-alteryxpnv01 - Remote Desktop Connection.png

mbarone
16 - Nebula
16 - Nebula

Ha ha - it looks like @Emil_Kos and I were building out pretty much the same solution at the same time! 🙂

Emil_Kos
17 - Castor
17 - Castor

Hi @mbarone,

 

Yes, that is true.

 

Initially, I wanted to use one tool with the formula below:

 

IIF([Row-1:ACTION] = 'NEW' AND [ACTION] = 'CANCEL' OR [ACTION] ='NEW' AND [Row+1:ACTION] = 'CANCEL', 'Y', null())


It didn't work so I moved to the nested if function to make it work:

 

IF [Row-1:ACTION] = 'NEW' AND [ACTION] = 'CANCEL' THEN 'Y' ELSEIF [ACTION] ='NEW' AND [Row+1:ACTION] = 'CANCEL' THEN 'Y' ELSE null() ENDIF

 

 

Emil_Kos_0-1618576710003.png

The output:

 

Emil_Kos_1-1618576738808.png

Mission accomplished 😀

mbarone
16 - Nebula
16 - Nebula

Nice!!  I knew it could be done, but was a bit too lazy this morning LOL!

Emil_Kos
17 - Castor
17 - Castor

Hi @mbarone,

 

I know you are aware of how to do that 😀

 

I was too busy and needed to finish something fast. I just needed to make it work 🤣

mbarone
16 - Nebula
16 - Nebula

I know how that is!  I think I have about 100 hours worth of "I need to know how to do that and will set some time aside one day to figure it out" projects LOL!

barkat
6 - Meteoroid

Thank you. That's vert helpful. 

Labels
Top Solution Authors