Engine Works

Under the hood of Alteryx: tips, tricks and how-tos.
jmuskovitz
6 - Meteoroid

Have you ever had a table where you wanted to use odd/even row coloring, but wanted the grouping to vary based on the data? Perhaps you have a field in your data like this:

Field

1

1

1

2

2

3

4

4

4

 

It would be nice if you could have all of the "1" rows white, the "2" rows gray, and so on. With the new Table Rules feature in Alteryx 4.1, accomplishing this is a snap!

Table Rules allow you to override any of the standard (or even not so standard) styles used in tables. You can do this for individual rows, columns, or cells. You get to specify a condition for when the override should happen, and then what styles to override. You can create any number of rules for a table.

 

In the following example, I wanted to alternate the background color for the rows whenever the City field changed. I accomplished this by using the Tile tool, which assigned a unique value to each City. I then used two rules to override the background color in the table, one which changed the color for odd-numbered tiles, and one for even-numbered tiles. You can download the module here.

 

Here is the result:

 

This is a Basic table with default odd/even coloring. Although the original data is sorted alphabetically by the School Name, we pass the data through a Sort tool keyed to the City field, and use the default odd/even coloring settings in the table.

 

This is a Basic table which uses the new Row Rules feature to alternate colors when the name of the city changes. This is accomplished by using a Tile tool, and setting it to Unique Value and choosing the City field. This assigns each item a Tile_Num field, with each City getting its own value. We will use this value to override the odd/even coloring.

 

We add two Row Rules to the table, as follows:

Apply Formula: Mod([Tile_Num], 2) == 1

Style: Background Color: White

and

Apply Formula: Mod([Tile_Num], 2) == 0

Style: Background Color: 240,240,240

 

The Mod() function divides the Tile_Num value by 2 and returns the remainder. For odd values, this returns 1. For even values, this returns 0. Thus the two rules each apply to their respective rows.

Comments
sfyodor
7 - Meteor

Thanks for sharing.

 

Which formula would I use to assign a row rule to a range of numbers?

 

I have a range from 0-100, but I only need 0-5 colored red and 6-10 colored yellow.

 

I used a when argument for the first set, but not sure about a formula for the second set aside from creating a row rule for each number from 6 to 10.

 

Thanks.