Zum Inhalt springen

Lektion 7 · Preparing Data

Filter, Sort, Sample and Unique

Choose and order rows in Alteryx with Filter, Sort, Sample, Select Records, Record ID, Unique and Tile, and learn how null values behave in conditions.

After you fix types, you usually need to choose which rows to keep and in what order. Designer has a group of small tools for this. Each does one job, and together they cover what SQL does with WHERE, ORDER BY, LIMIT and DISTINCT.

This lesson shows each tool and the traps around nulls and order.

Filter

The Filter tool tests each row with a condition and sends it to one of two outputs: T for true and F for everything else. You can use the basic mode, which builds a simple condition from menus, or write a custom expression:

TEXT
[country] = "Portugal" AND [amount] >= 100

Both outputs are useful. Send the T side to the next step, and send the F side to a Browse tool or a reject file so you can see what you left out.

A condition that cannot be true because a value is null sends the row to F. If you need missing values, test them explicitly with IsNull([amount]).

Python Stand-in: where do null values go in a filter?

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.

To keep only the rows with a missing value, use IsNull([amount]) as the condition and read the T side.

Sort

Sort orders rows by one or more fields, ascending or descending. With several fields, later fields break ties. Sorting is expensive on large data, so sort only when a later step or the reader needs it.

Text and numbers sort differently. If your numbers are text, "100" comes before "9". Fix the type first.

Sample, Select Records and Random % Sample

  • Sample takes a part of the data, for example the first N rows, the last N rows, or every Nth row. It can work per group when you choose grouping fields.
  • Select Records keeps rows by their position, such as rows 1 to 10.
  • Random % Sample keeps a random fraction or number of rows.
  • Create Samples splits data into groups, which is common before model building.

"First N rows" depends on row order. To get the three largest orders per region, sort by region and amount first, then use Sample with grouping on region.

SQL Stand-in: top 2 orders per region

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

Record ID

Record ID adds a sequence number to each row. Use it to:

  • Remember the original order before a sort or join.
  • Give every row a key for later reference, which some tools need.
  • Trace a single row through a long workflow.

The numbers reflect the order at the moment the tool runs, so they can change if the input order changes. They are not permanent business keys.

Unique

Unique looks at the fields you choose. The first row of each combination goes to the U output, and later rows go to D.

Which fields you choose defines "duplicate". Choosing only email treats two rows with the same email as duplicates even if the names differ. And because "first" depends on order, sort so that the row you want to keep comes first, for example by most recent date.

Python Stand-in: keep the newest row per email

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.

Text matching in Unique can treat different capitalization or spaces as different values, so clean the key first. The cleansing lesson shows how.

Tile

Tile assigns each row to a bucket, or "tile". You can create groups with equal numbers of records, or define other methods, such as manual cutoff values. Use it for segments like customer spending quartiles. Check how ties and uneven group sizes are handled by looking at the counts per tile.

Building a reject stream

In production work, rows that fail a rule should not simply vanish. Connect the F output of each validity filter to a Formula that adds a reason, such as "amount missing". Then union all those rejects into one output file. The result is a short list that a person can read and fix at the source.

A reject stream also lets you check row accounting: the rows that passed plus the rows that were rejected should equal the rows that came in. If the numbers differ, a row was lost or duplicated somewhere.

When you combine several conditions in one filter, you lose the information about which condition failed. For a clear reason, either use several filters in a row or calculate a reason column first with a Formula and then filter on whether that column is empty. The second approach keeps the canvas small and records only the first failed rule, so order the rules by importance.

Order of operations

Filter before you sort, so the sort has less work. Sort before you take the first rows or remove duplicates, so the surviving rows are the ones you intend. If a Summarize or a Join sits between the sort and the step that needs it, sort again afterward instead of assuming that your order survived.

Practice task

Build a table of ten orders with a customer, a date and an amount. Include a missing amount and two orders from one customer on the same day. Your goal is the latest order for each customer.

Write down the sort fields you need, including a tie-breaker for the two orders on the same day. Then use Unique on the customer, and check both outputs. Confirm that the U and D counts add up to ten. Change the sort direction and observe which row survives now. This shows how much the result depends on a step that Unique itself does not perform.

Common mistakes

Do not run Unique or Sample "first N" on unsorted data when you care which row survives. The result may change from run to run or from one engine to another.

  • Forgetting the F output, so rejected rows disappear without a trace.
  • Using a condition that silently excludes nulls.
  • Treating Record ID as a stable identifier.

Check your understanding

Quick check · 3 questions

of 3 answered You scored / 3 · perfect!

  1. 1. Where does the first row of each unique combination go in the Unique tool?

    U holds the first occurrence; D holds later duplicates.
  2. 2. A row has a null amount and the filter is amount at least 100. What happens?

    A null comparison is not true, so the row leaves through F.
  3. 3. How do you get the two largest orders in every region?

    Sorting sets the order, and grouping applies the sample to each region.

Summary

  • Filter splits rows into T and F outputs; test nulls explicitly.
  • Sort sets order, and only some steps need it.
  • Sample, Select Records and Random % Sample take subsets.
  • Record ID numbers rows, Unique separates duplicates and Tile makes buckets.

Next: Cleansing Data and Handling Nulls

Dein Fortschritt wird in diesem Browser gespeichert. Kein Konto nötig.