Alteryx Designer Desktop Discussions

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

Multirow formula

rajputakansha
8 - Asteroid

Hi,

 

I am trying to use Multi row formula to compare the Old values from previous period and New values from current period for each  unique ID.

My output should be "Desired Value"

PeriodIDNew ValueOld ValueDesired Value
P1A100017000
P2A170019000
P3A190025000
P4A27003100-200
     
P1B140010000
P2B100018000
P3B20002400-200
P4B240058000
     
P1C300032000
     
P3D640068000

 

If I use [Row-1:Old Value]-[New Value], I am getting:

PeriodIDNew ValueOld ValueDifference in Old value and new value each period
P1A10001700-1000
P2A170019000
P3A190025000
P4A27003100-200
     
P1B14001000-1400
P2B100018000
P3B20002400-200
P4B240058000
     
P1C30003200-3000
     
P3D64006800-6400

 

Can anyone please suggest a correct logic for this?

 

Thanks for your help!

 

5 REPLIES 5
AhmedAlZabidi
7 - Meteor

Hello,

 

You can use the following formula:

 

if IsNull([Row-1:Old Value]) or [Row-1:Old Value] == 0 then 0 else [Row-1:Old Value]-[New Value] endif

Martyn
9 - Comet

In the Multirow Formula tool you need to take into account what you have specified for "Values for Rows that don't exist".

 

The issue is that the first row in each group is using a zero value for the [Row-1:Old Value].

 

Put some extra logic in to take this into account.

 

For instance

 

IF [Row-1:Old Value] = 0

THEN 0

ELSE [Row-1:Old Value]-[New Value]

ENDIF

rajputakansha
8 - Asteroid

Thanks @AhmedAlZabidi , @Martyn ,

 

The logic does work well when I already have some 0s the New and Old value columns.

For example:

 

PeriodIDNew ValueOld ValueDifference in Old value and new value each period
P1A000
P2A000
P3A190025000  [This should be -1900]
P4A27003100-200

 

Can you please suggest how to work around in this case?

 

Thank you!

rajputakansha
8 - Asteroid

Correction: The logic doesn't work well when I already have some 0s the New and Old value columns.

T_Willins
14 - Magnetar
14 - Magnetar

Hi @rajputakansha,

 

You can solve this by changing the Multi-Row Formula Values for Rows that don't Exist to Null while keeping the field type to Int32.

 

Multi Row.JPG

 

Labels