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

How to subtract a value only for N rows where N is based from a field

FabioP
8 - Asteroid

Hello everyone!

 

I have a flow where I need to do a subtraction but only for a number of rows based on a field value. For example:

 

antes.PNG

 

On the table above I need subtract "1" (the Target value) from the QTY, but only for the first 4 lines, where the number 4 comes from Diff.

Like this:

 

depois.PNG

 

Is it possible?

Could anyone help me?

5 REPLIES 5
jdunkerley79
ACE Emeritus
ACE Emeritus

Yes, this is possible.

jdunkerley79_0-1601405758671.png

 

Use a RecordID tool to add a row number 

And then a formula to adjust the QTY:

 

iif([RecordID]<=[Diff],1,0)+[QTY]

 

Finally, a select to drop the RecordID

atcodedog05
22 - Nova
22 - Nova

Hi @FabioP ,

 

Here is a workflow for the task.

 

Input

atcodedog05_1-1601405965363.png

Output

atcodedog05_2-1601406007773.png

Formula

IF [RecordID]<=[Diff] 
THEN [QTY]-[Target] 
ELSE [QTY] ENDIF

atcodedog05_0-1601405941830.png

Hope this helps : )

 

If this helps please mark the post as solution.

vizAlter
12 - Quasar

Hi @FabioP — You can solve this through "Tile" tool as well:

 

vizAlter_0-1601406745942.png

 

Tile tool configuration (hope, no duplicates in your "Code" field):

vizAlter_0-1601407019036.png

 

atcodedog05
22 - Nova
22 - Nova

Happy to help : ) @FabioP 

 

Cheers and Happy Analysing : )

vizAlter
12 - Quasar

@FabioP — Thank you!

Labels
Top Solution Authors