Advent of Code is back! Unwrap daily challenges to sharpen your Alteryx skills and earn badges along the way! Learn more now.

Alteryx Designer Desktop Discussions

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

Converting strings to numbers when minus signs are on the right

dmag427
5 - Atom

I have a text file of invoiced and paid amounts that I'm manipulating and converting to an Excel file using Alteryx (which I'm new at).  I'm having issues converting some of the fields from strings to numbers, in part because some of the numbers are negative and have a dash to the right (e.g. 5,371.58-).  I've read some of the other posts on this sight, and tried using various combinations of "ToNumber" and "RegEx" formulas, but so far I've only succeeded in eliminating the negative sign, rather than converting the text string to a negative number.  Any guidance would be appreciated. 

 

 

4 REPLIES 4
MarqueeCrew
20 - Arcturus
20 - Arcturus

Try this:

 

IIF(Contains([Field],”-“),”-“+trim([Field{,”-“),[Field])

 

cheers,

Mark

 

 

Alteryx ACE & Top Community Contributor

Chaos reigns within. Repent, reflect and restart. Order shall return.
Please Subscribe to my youTube channel.
dmag427
5 - Atom

Thanks for the response.  Unfortunately, I'm getting a "Malformed Function Call" error message related to the first field reference, which I'm struggling to address

MarqueeCrew
20 - Arcturus
20 - Arcturus
Sorry,

IIF(Contains([Field],”-“),”-“+trim([Field],”-“),[Field])

Typo

You are using an in-line if statement

If-then-else-endif

If the string contains a - character,
Then it is - plus the original value without any leading or trailing- signs. Else if no - characters are found, just keep the original value.

I used the trim function in case a - sign is on the left side

Cheers,

Mark
Alteryx ACE & Top Community Contributor

Chaos reigns within. Repent, reflect and restart. Order shall return.
Please Subscribe to my youTube channel.
KANIKA3393
5 - Atom

Hi dmag427,

I am also stuck with the problem you faced. Can you guide how were you able to convert the string to an integer/ double data type post bringing the minus from the end to the beginning? Whenever I change the data type using Select, it takes the first digit only.

Thanks in advance!

Labels