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

Value extraction and add to new column

Baz123
8 - Asteroid

Hi,

 

I have a data set that has a preformatted workbook. I have managed to setup a workflow that dynamically extracts the table required, but I have some more work left to get it formatted for end use.

 

The table looks like the below:

 

IDCompare
SHT APR >90M <150M 
  
SHT APR <100K 
  
  
  

 

What I need to do is extract the value from the ID column (the second value = upper limit in the case with a range of values as seen in the first row) and then add the value to the Compare column all the way down to the next ID so it would look like this:

 

IDCompare
SHT APR >90M <150M150,000,000
 150,000,000
SHT APR <100K100,000
 100,000
 100,000
 100,000

 

I cant seem to figure out how to extract the value if there is a range, and then convert that to the numerical value.

 

Late edit / update - ID values are longer than shown. Should look like the above, but with extra data on end of string like this :

 

SHT APR >90M <150M ABC DEF GHI

 

Thanks.

8 REPLIES 8
ShankerV
17 - Castor

Hi @Baz123 

 

One way of doing this.

 

ShankerV_0-1685505983310.png

 

 

Many thanks

Shanker V

ShankerV
17 - Castor

Hi @Baz123 

 

Step 1: Input tool

 

ShankerV_0-1685506873642.png

 

 

Step 2: 

 

ShankerV_1-1685506895007.png

\s.(\d+)(\u)$

 

 

ShankerV_2-1685506920411.png

 

 

Step 3:

 

ShankerV_3-1685506934063.png

 

IF [RegExOut2]="M"
THEN [Compare]*1000000
ELSE [Compare]*1000
ENDIF

 

ShankerV_4-1685506943884.png

 

 

Step 4:

 

ShankerV_5-1685506974347.png

 

IF Isnull([Compare])
THEN [Row-1:Compare]
ELSE [Compare]
ENDIF

 

 

ShankerV_6-1685506984816.png

 

Many thanks

Shanker V

flying008
15 - Aurora

Hi, @Baz123 

 

Another way for you:

 

 

 

ToNumber(iif(IsEmpty([ID]),[Row-1:Compare],IIF(Right([ID], 1) in ('M','k'),Replace(Right([ID], Length([ID]) - FindString([ID], '<') -1), Right([ID], 1), Switch(Right([ID], 1),Null(),'M','000000','k','000')), Right([ID], Length([ID]) - FindString([ID], '<') -1))))

 

 

 

录制_2023_05_31_12_25_27_790.gif

 

Input Output 
ID IDCompare
SHT APR >90M <150M SHT APR >90M <150M        150,000,000
           150,000,000
SHT APR <100K SHT APR <100K              100,000
                 100,000
                 100,000
                 100,000
Baz123
8 - Asteroid

Hi @ShankerV - I will see if I can get it to work

 

@flying008 - The formula seems to work, however I forgot to add in that the ID values have extra characters on the end of the string so this:

 

SHT APR >90M <150M

 

Is actually this

 

SHT APR >90M <150M ABC DEF GHI

 

Can your expression be modified to trim the string down? It looks like Alteryx is throwing a conversion error because of that.

 

Thanks.

Raj
16 - Nebula

By using the regular expression pattern <(\d+(?:M|K)), you can extract the value that follows the "<" symbol and consists of one or more digits followed by either "M" or "K".

 

I think you will be able to do the remaining part
Hope this helps.

 

Raj
16 - Nebula

use this afterwords
If Contains([RegExOut1],"M") then replace([RegExOut1],"M",",000,000") elseif Contains([RegExOut1],"K") then replace([RegExOut1],"K",",000") elseif [RegExOut1]= null() then [Row-1:RegExOut1] else "0" endif

 

Raj_0-1685510424182.png

 

flying008
15 - Aurora

Hi, @Baz123 

 

Please try this Multi-Row formula:

 

ToNumber(iif(IsEmpty([ID]),[Row-1:Compare],IIF(Right(REGEX_Replace([ID], '^.*<(\d+[Mk]?).*?$', '$1'), 1) in ('M','K'),Replace(REGEX_Replace([ID], '^.*<(\d+[Mk]?).*?$', '$1'), Right(REGEX_Replace([ID], '^.*<(\d+[Mk]?).*?$', '$1'), 1), Switch(Right(REGEX_Replace([ID], '^.*<(\d+[Mk]?).*?$', '$1'), 1),Null(),'M','000000','K','000')), REGEX_Replace([ID], '^.*<(\d+[Mk]?).*?$', '$1'))))

 

BTW, if you want use simple formula, then can flow 2 steps:

Spoiler
1- 
<(\d+[Mk]?)

2- 

ToNumber(iif(IsEmpty([ID]),[Row-1:Compare],Replace([ID], Right([ID],1), Switch(Right([ID],1), Right([ID],1), 'M','000000','K','000'))))


flying008_0-1685515738526.png

 

 

Baz123
8 - Asteroid

Thanks @flying008 - I used the last method here in combination with my other steps to get what I needed.

 

Appreciate the help!

Labels
Top Solution Authors