Alteryx Designer Desktop Discussions

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

Dynamically create new column on difference between two columns

CCrawford94
7 - Meteor

Hello all, 

 

I need to take the difference of two columns to get the difference. This needs to be dynamic because the name of the two columns that the difference are based on years and the years can change but it will always be a recent year minus a past year. I am trying to add this to a workflow so that when i run it with different year sets it will not break. 

For example I start with data like this:

20122013
702877637933
59628285726
164553114312
12077621239885
257656118491
19180347450
143671100259
72487362962
1901396

1674654

 

and end with this:

20122013Difference
702877637933-64944
59628285726-510556
164553114312-50241
1207762123988532123
257656118491-139165
19180347450-144353
143671100259-43412
72487362962-661911
19013961674654-226742

 

Please any help would be great.

3 REPLIES 3
NicoleJohnson
ACE Emeritus
ACE Emeritus

Check out the attached example (version 11.8)... I used Text input to create a "Year 1" and "Year 2" column with no data, then unioned it to the data provided by position (which renames your columns from whatever year they are to "Year 1" and "Year 2"). You can then use a formula to calculate Year 2 - Year 1 to get your Difference... and then a Dynamic Rename to rename the columns with the original years (choose the Take Field Names from Right Input Metadata option in the Dynamic Rename tool).

 

Should work no matter what the year column names are in your original data.DynamicYears.JPG

Hope that helps!

 

Cheers,

NJ

CharlieS
17 - Castor
17 - Castor

@CCrawford94

 

If the years are the only two columns, @NicoleJohnson created a very elegant solution. I have a different package on the same solution in case there are more columns of data besides the two years of interest.

 

 

 

AnkitDwivedi6
7 - Meteor

Hello i really likes your solution but when i am applying this in may problem i am not getting desired output. Could you please check if there is any amendment required? Here Dates are dynamic in main data sheet.

 

Field1Field2Field3Date1(PREV DATE)Date2(LATEST DATE)DIFF (DESIRED COLUMN)
ABC125LGM1212-15(-15)-12
DFG125XRF3418-16(-16)-18
LKM758TRT56823636-82
Labels