Alteryx Designer Desktop Knowledge Base

Definitive answers from Designer Desktop experts.

How To: Remove Leading/Trailing/All Whitespace

MattD
Alteryx Alumni (Retired)
Created

There are a couple of different whitespace situations you might get yourself into, but the schematic below (from the attached example Remove Whitespace.yxmd) has you covered in all of them:

Removing Whitespace.PNG

Most of the approaches make use of the Formula Tool’s trim() functionwhich, without a second argument, defaults to trimming whitespace from your strings. You can also use the Data Cleansing toolto clean your fields for you! Master it here.

Attachments
Comments
KB
7 - Meteor
Thanks MattD the regex_replace did the trick for me. Thank you for sharing
jcardoso
8 - Asteroid

Hi, how do we stop Alteryx from removing string spaces automatically?

I've created a Python script to read input excel files,  but when i have sheet names with trailing spaces, Alteryx removes them automatically on the output. 

The Python throws, for example "DESKTOP EG "

Using the same script in Alteryx throws "DESKTOP EG",

Then if i want to read that sheet in another macro with a Dynamic Input, i cannot, because the space was removed, so an error message appears: 
"Record #1...does not match a sheet or named range in ... or the Excel file is corrupt.
How can i prevent that? Thank you.

johnc_
5 - Atom

Hi jcardoso,

 

I am having the same problem as you.

 

Did you ever find a solution?

 

Cheers

MikeLR
8 - Asteroid

This was really helpful thanks Matt. I was previously using the Data Cleansing tool to remove the space from all postcodes in my input file. That tool alone was taking 148 seconds. Using the formula tool with regex_replace([Postcode],"\s","") only takes 10 seconds 😁

Victouf
7 - Meteor

Hi,

 

Very useful, thanks a lot. What if I need to remove whitespaces in 3 different colums at the same time ? Do I have to create 3 different formulas within the same formula tool ?

 

Thanks

arlissbanks
5 - Atom

Victouf, you can use a Multi-field formula to select multiple fields to run the same formula on.

CammyPhillips
8 - Asteroid
Spoiler