Showing results for 
Search instead for 
Did you mean: 

Alteryx designer Discussions

Find answers, ask questions, and share expertise about Alteryx Designer.

Formula to add the prefix B when it is numeric value only


We are using the below formula to add the prefix B if the value in the column is whole number, but this formula is not working correctly as it is just looking at the first value not the whole value. For example if value is 1A219 it should add the prefix B as it contains alpha as well. We are expecting only the B prefix to be added if the value is whole number i.e. 64972 not alpha numeric. Please advise


IF ToNumber([Counterparty]) >0 then "B"+[Counterparty] else [Counterparty] endif


How about using this formula?


if REGEX_Match([Counterparty], '\d+') then "B"+[Counterparty] else [Counterparty] endif

The ToNumber function parses the string as far as it can - i.e. 1A234 becomes 1.


I suggest:

IF REGEX_Match([Counterparty], "^[0-9]+$") then "B"+[Counterparty] else [Counterparty] endif

This checks the string is purely numerical.