Step 1: Filter the data
We start by opening the previously created “Altoona Crime Rates.tde” (Tableau data extract) – once opened, the data source page appears (your columns might be ordered differently):
- Canvas shows that we are working with a data extract – the title says “Altoona Crime Rates Extract”; and “extract” is written in a number of other places on the page.
- The Connection with the data extract, however, is Live. This makes sense, because we are working with a live version the previously created Tableau data extract.
We want to focus on juvenile offenses, so we will filter our all rows without them:
- In the upper right corner of canvas click under Filters on Add.
- New window pops up: click on Add…
- Another window pops up: choose Juvenile Total.
- Another window pops up: move from box saying Range of values to box saying At least, and set it to at least 1. Press OK.
- You are returned back to the previous pop-up window which now shows your newly
created filter for Juvenile Total being “greater than or equal to 1”. Press OK here too.
Step 2: Sort the data
If you scroll to the right end of the data grid, you can notice 3 things:
- The Filters indicator in canvas now shows 1 filter instead of 0 before.
- The right side of the data grid now shows we are looking at 798 rows of data – there was over 1,000 rows when we started, but only these 798 have at least 1 juvenile offense.
- The Juvenile Total column in the data grid confirms that all values are at least 1.
Now that we filtered down to juvenile offenses, how do we sort by the size of individual observations?
- Click on the sorting icon once – it sorts Juvenile Total in ascending order.
- Click on it second time – it sorts Juvenile Total in descending order.
- Click on it third time – it sorts Juvenile Total back to its original order in the dataset.
You can sort any other column in the same way.
Step 3: Sort the data on aggregate level
What if you instead want to sort the data on aggregate level? For example, what if you want to see the list of months with the highest numbers of juvenile offenses? Something like this:
For this, you need to go into the worksheet (click on Sheet1, just like you did in Module 1):
- Drag Measure Juvenile Total into the Rows shelf.
- Drag Dimension Month into the Columns sheet, and update
its
frequency from discrete yearly blue “YEAR(Month)” to continuous monthly
green “MONTH(Month)” like we did in Module 1 – in the drop-down menu, make
sure you change from “Year (2015)” to the second option for
month, “Month (May 2015)”, and not the first, “Month
(May)”. - Then, when
it is already green, change “MONTH(Month)” from continuous into a
discrete variable – it will turn back blue, but as “MONTH(Month)”:
You have to follow the above 2-step order to get our desired view. If you change Month from discrete yearly “YEAR(Month)” to discrete monthly “MONTH(Month)” right away without changing it to continuous monthly first, Tableau would automatically aggregate one month across all years (e.g. January 2013, January 2014, etc. under January), which we don’t want here. The only reason we are changing it to discrete in the end is because you cannot sort continuous variables, and here we do want to sort by month.
- Hover the mouse in the view above the vertical axis with Juvenile Total – a sorting icon appears. Use the sorting icon to sort in a descending order:
And that’s how you get the sorting from the previous page! When sorting, Tableau automatically changes the graph from a line to bars. Now it is easy to read: the month with highest number of juvenile offenses in the
dataset is May 2015, followed by October 2015.
Depending on your version and settings of Tableau, your resulting view may not clearly show you May 2015 under the highest bar. Remember from Module 1 that you can always hover above any bar, and the mouse
will pop out a new window showing the bar’s values.
Review
We just learned how to filter, and sort the data in Tableau:
- To filter data, use the Filters
tool in canvas. - To sort data on individual level, use the sorting icon in the data grid.
- To sort data on a more aggregate level, you need to combine variables in the worksheet, and then sort the resulting graph, which may require changing a continuous variable into a discrete one.
Challenges:
Practice what you just learned by answering the following
questions. Answer each question in a new worksheet, or by using the data source
page.
- Looking at the resulting data, what is the most common crime that male juvenile offenders committed in one month? What about the female juvenile offenders? Hint: solve this by simply using the data grid.
- In what month did both of the above common crimes occur? Hint: also solve this using the data grid.
- Looking at the resulting data, what is the most common crime that juvenile offenders committed across all months? How many times was it committed? Hint: this is an aggregate problem, so use the worksheet to create a new view between 2 variables, sorted by the variable of interest (type of
crime). - Change the data source page and worksheet so they look at adult offenders rather than juvenile offenders, and answer questions 1-3 for them.
Next Page: Previous Page: