Community Spring Cleaning week is here! Join your fellow Maveryx in digging through your old posts and marking comments on them as solved. Learn more here!

Alteryx Designer Desktop Discussions

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

String value for a numeric field

dbuz
7 - Meteor

Hello everyone,

 

I'm struggling with trying to write a "N/A" string for a numeric field.

 

To be more specific, my formula tool needs to calculate the difference between two fields (so the field type should be numeric), but in case one of them is blank, I would like Alteryx to mark the record as "N/A".

 

While trying to do this, you receive the following error message: The formula [Formula Name] resulted in a string but the field is numeric. Use ToNumber (...) if this is correct.

 

Formula used so far:

 

IF !IsNull([Numeric variable #1]) THEN ToNumber([Numeric value #1]-[Numeric value #2]) ELSE "N/A" ENDIF

 

Are you aware of any alternative solutions to achieve this?

 

Thanks in advance!

 

D.

4 REPLIES 4
apathetichell
18 - Pollux

"n/a" is a string - null() is numeric any type of missing data.

 

you can have the null() converted to a display value ie ("n/a") in a table tool, but you can't have that value in a numeric field.

dbuz
7 - Meteor

@apathetichell ,

 

Thanks for your prompt reply!

 

So there is no way to have "N/A" written in the field in the output file in excel instead of having it empty? If so, how can I achieve it? I am asking this, because the "Null ()" formula ends up producing an empty record.

 

D.

markcurry
12 - Quasar

Hi @dbuz , as @apathetichell mentioned your field will need to either be a numeric field showing the result of the calculation, or a string if you want to show "N/A".  You could convert your numeric result to a string, and output everything as a string, but Excel will show the message 'The number in this cell is formatted as text or preceded by an apostrophe'.   Would outputting two columns be an option?   Output a "N/A" beside in the string field beside the numeric field.

 

apathetichell
18 - Pollux

@dbuzas @markcurry mentioned you can either convert to string using a multi-field formula with all of your numeric fields selected and the formula of:

 

if isempty([_currentfield_] then "N/A" else tostring([_currentfield_]) endif

 

 

before ending as your last tool before output...

 

There's a way to do it in TABLE which "should" allow you to keep your output as numbers in excel. see the screenshot attached.

2021-06-11.png

Labels