Say you want to output the top 10 values of a table in Alteryx. You sort your values, use the Sample tool to select the top 10 rows, and head to the output, only to realize a few rows tied for 10th place have been cut off. What to do? When I ran into this myself, I solved it by adding a rank to my table. In this walkthrough, I'll show how to generate a rank in Alteryx and use it to keep those tied rows in your final output. I'll be using the Kaggle sourced TMDB Movie Metadata dataset used in Alteryx Challenge #491; feel free to download the data and follow along.

First, pick which kind of rank you want to use. This determines how ties are handled (and therefore which rows make it into your final output) as well as which formula you'll need. I'll use competition rank, also known as standard rank, which skips ranks after a tie (1, 2, 2, 4…). It's the most common option, but you could also use dense rank (1, 2, 2, 3…), modified competition rank (1, 3, 3, 4…), or unique rank (1, 2, 3, 4…). If you choose one of these, be sure to adjust your formula accordingly.

In this example, we'll output the 10 films with the highest budgets. Start by inputting your dataset, keeping only the columns you need, and selecting the correct data types for sorting. In this example, that would be selecting "title" and "budget" from tmdb_5000_movies.csv, and changing “budget” from a string (V_String) to an integer (Int64).

Next, connect a Sort tool and sort by the metric you're ranking. Here we’ll sort by budget in descending order.

Then, connect a Record ID tool. It assigns a sequential number to each row, which our formula will need shortly.

Now we're ready to create the rank. Connect a Multi-Row Formula tool, set it to Create New Field, name it (I'm using Budget Rank), and set the data type to Int32.

Next comes a crucial step: under Values for Rows that don't Exist, select 0 or Empty. If you skip this, your formula will return all Null values.

Now use this formula pattern for competition rank:

IF [Metric] = [Row-1:Metric] THEN [Row-1:Rank] ELSE [RecordID] ENDIF

For our sample data, that formula would look like:

IF [Budget] = [Row-1:Budget] THEN [Row-1:Budget Rank] ELSE [RecordID] ENDIF

This tells Alteryx to copy the rank from the previous row when the two values are equal, and to use the RecordID as the rank when they aren’t equal.

Run the flow to confirm the formula works and isn't returning Nulls. If you know where a tie occurs, check those rows to make sure they're handled correctly.

Next, connect a Filter tool and filter on the rank column. Since I want the top 10, I'll filter for [Budget Rank] <= 10.

Run the flow and check the True anchor. Mine returns 16 rows because there's a massive tie at 9th place. If we had used the Sample tool, it would have cut these ties off arbitrarily.

Finally, connect a Select tool to drop the RecordID column and any other columns you no longer need.

And that's it! You can now browse or output a complete top 10 that includes any ties. With a rank in place, your top 10 is no longer at the mercy of the Sample tool's cutoff.