This article describes how to use a Calculation to filter and order a visualization. This can be useful when you are doing a lot of filtering in your document and have different brands for different demographics that you'd like to show. Similarly, you can use this approach to order rows/columns in a visualization based on the rows/columns of a separate input.
This example walks you through how to go from a visualization ordered as the input table is - this is showing top 2 boxes for cola brands:
To a state where only certain bars are shown and in a particular order -- below shows the same top 2 box data, but only for the top 4 brands in the awareness table:
- A visualization without tests based on a table of data (rather than variables). See How to Create a Column Chart from a Table.
- A Calculation listing the rows/columns to show in that order in the visualization. Note, the names must match the table used to create the visualization exactly.
For my example, I will use the following table as an input to my visualization.
I will also use the following awareness table in my Calculation.
- After creating your visualization, you need to create a Calculation that lists the rows/columns you want to show in that particular order. To do so, click the Calculation = button and click your page to create a blank custom R calculation.
- Create your own custom calculation to create a series of the row or column names you'd like to show in that order. My code for this example is below. It uses the Awareness SUMMARY table above and pulls off the top 4 brands in order.
- Click Calculate. You'll see an output similar to below:
- Now we can use this Calculation to filter/order our visualization. Select your Visualization.
- In the object inspector, change Inputs > ROW MANIPULATIONS > Select rows to show by > Calculation output.
- In the Rows to show field, select or type in the Properties > GENERAL > Name of your Calculation made in step 1.
- [OPTIONAL] To do this for your columns you'd use: Inputs > COLUMN MANIPULATIONS > Select columns to show by and Columns to show.