Skip to content

Lesson 8 ยท Preparing Data

Cleansing Data and Handling Nulls

Clean messy fields with the Alteryx Data Cleansing tool, tell nulls from empty strings, standardize text and decide when replacing missing values is safe.

Real data is messy: extra spaces, odd capitalization, hidden characters and missing values. Small differences like these break joins and produce wrong totals. Designer's Data Cleansing tool handles the common cases, and the Formula tool handles the rest.

This lesson shows what the tool can do and, just as important, what cleaning might hide.

What Data Cleansing offers

According to the Designer help, the tool works on the fields you select and can:

  • Remove null rows, but only rows where every column is null.
  • Replace nulls with a blank for text fields, or with 0 for numeric fields.
  • Remove unwanted characters: trim leading and trailing spaces, reduce repeated whitespace, or remove all whitespace, letters, numbers or punctuation.
  • Change case to upper case, lower case or title case.

Newer versions also offer a Data Cleanse Pro tool with extra options, such as dealing with invisible characters and turning blanks into nulls. It requires the AMP engine. Check which tool your version includes.

Some defaults replace nulls. A 0 is not the same as "unknown". If you fill a missing temperature or price with 0, averages change and nobody can tell the difference later. Check the default options each time.

Null, empty and blank

These look similar on screen but are different:

Value Meaning
Null No value
Empty string A text value with no characters
Spaces only Text that looks empty but is not

The row-removal option ignores rows that contain empty strings, because empty strings are not null. In formulas, IsNull([field]) tests for null, and IsEmpty([field]) tests for null or an empty string.

Python Stand-in: nulls, empty strings and blanks

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Standardizing text keys

Before you match two sources, make the keys look the same. A typical expression in a Formula tool is:

TEXT
Uppercase(Trim([customer_code]))

Then check what is left: non-breaking spaces from web pages, tabs, leading apostrophes and different dash characters often survive a simple trim.

Python Stand-in: find and fix hidden characters

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Removing characters carefully

"Remove punctuation" can damage values. It would remove the decimal point from 12.50, the hyphen in AB-12 and the dot in an email address. Select only the fields that need it, and test on examples that contain tricky values.

Choosing how to treat missing values

Option When it fits Risk
Keep null You must show "unknown" Some calculations return null
Fill with a constant The meaning is clear, e.g. no discount means 0 Fake precision
Fill with a statistic Modeling, with care Hides uncertainty
Drop the row The row is useless without the value Bias, lost records

The Imputation tool in the Preparation category can replace nulls in numeric fields with a statistic such as the average or median. Record that you did so, for example in a new flag column.

TEXT
IF IsNull([discount]) THEN "missing" ELSE "provided" ENDIF

Add the flag before you replace the values.

A cleansing checklist

  1. Count nulls per field before changing anything.
  2. Trim and standardize keys.
  3. Check for impossible values, such as negative quantities or dates in the future.
  4. Decide a rule for each missing value and write it down.
  5. Compare record counts before and after.
Python Stand-in: a cleansing report before and after

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Notice that cleaning the names did not fix the negative quantity. Rules about values need their own checks, often a Filter that sends bad rows to a review file.

Where to clean, and how to show it

Clean as close to the input as possible, so every later step sees the same values. Keep the original column when the difference matters. For example, create customer_code_clean next to customer_code and match on the clean one. If someone questions a result, you can show exactly what the source sent.

Report your findings to the people who own the source. If many rows have a missing region, a workflow can fill them, but only the source team can stop the problem from happening. A small summary output with counts of nulls and rejected rows per run makes trends visible. A sudden jump in these numbers is often the first sign that an upstream system changed.

Finally, write each cleaning rule as a sentence in an annotation, such as "Blank discount means no discount, confirmed by the sales team". A rule without an owner is only a guess.

Cleaning is not validating

Cleaning changes how a value is written. Validation asks whether the value is acceptable. " pt " can be cleaned into PT, but only a comparison with an approved list tells you whether PT is a country you serve. Build both steps: clean first, then validate, and send failures to a review output with a reason. This order prevents valid values from being rejected only because of a stray space.

Practice task

Create a Text Input table with a customer_code column that contains a leading space, a trailing space, mixed capitalization, an empty value and a code with punctuation. Add a numeric discount column with one missing value and one zero.

Before you run anything, write the output you expect after trimming and uppercasing. Then turn on one cleaning option at a time and compare. Check whether the punctuation survived, whether the empty value is null or an empty string and whether the missing discount can still be told apart from the real zero. If it cannot, add a flag column before the replacement and run the test again.

Common mistakes

  • Using cleaning options on all columns without looking.
  • Turning nulls into 0 before computing averages.
  • Cleaning the data so heavily that the original problem can never be traced.

Check your understanding

Quick check ยท 3 questions

of 3 answered You scored / 3 ยท perfect!

  1. 1. Which rows does the remove-null-rows option delete?

    It applies only when all columns are null, and empty strings are not null.
  2. 2. Why can replacing a missing price with 0 be harmful?

    0 is a real value, so totals and averages become misleading.
  3. 3. Which functions test for null versus null-or-empty?

    IsNull tests for null, and IsEmpty also matches empty strings.

Summary

  • Data Cleansing trims, changes case, removes characters and replaces nulls.
  • Null, empty string and spaces-only are different things.
  • Normalize keys before matching.
  • Decide missing-value rules on purpose, flag filled values and compare counts.

Next: The Join Tool

Your progress is saved in this browser. No account needed.