Skip to content

Commit

Permalink
Merge pull request #48 from LaunchCodeEducation/tableau-part-three
Browse files Browse the repository at this point in the history
Tableau part three
  • Loading branch information
jwoolbright23 authored Jun 20, 2024
2 parents 86488d8 + ffdbb81 commit c1a0de0
Show file tree
Hide file tree
Showing 17 changed files with 487 additions and 0 deletions.
38 changes: 38 additions & 0 deletions content/tableau-part-three/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
+++
pre = "<b>26. </b>"
chapter = true
title = "Tableau Part Three"
date = 2024-05-28T13:45:19-05:00
draft = false
weight = 27
+++

## Learning Objectives

Upon completing all the content in this chapter, you should be able to do the following:
1. Create basic and table calculations
1. Create parameters
1. Create a relationship between two tables

## Key Terminology

### Calculations
1. calculated field
1. basic calculations
1. table calculations
1. partitioning fields
1. addressing fields

### Parameters
1. Parameters

### Relationships
1. Relationships
1. root table


## Content Links

{{% children %}}


90 changes: 90 additions & 0 deletions content/tableau-part-three/exercises/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
+++
title = "Exercises: Tableau Part 3"
date = 2021-10-01T09:28:27-05:00
draft = false
weight = 2
+++

## Getting Started

1. Download this [Bike Sharing in Washington D.C. Dataset](https://www.kaggle.com/marklvl/bike-sharing-dataset).
- 2 CSV files total (`day.csv` and `hour.csv`).

1. Be sure to read the context and content about this dataset to better understand how and why data was collected.
1. Open the downloaded dataset in Tableau Public.
- Create a relationship between the CSV files.
- `Dteday` is a shared column between the two tables.

1. Create a new Tableau Public project to answer the below questions.
1. We are going to explore dates and create calculations and parameters with our data that answer our business issue.
1. Your final output will be a dashboard with at least 3 of your charts that provides data useful to the business issue.
1. Here are some [other fun facts about the DC Bike sharing program](https://en.wikipedia.org/wiki/Capital_Bikeshare)

### Business Issue:

The Bike Sharing program did very well in DC and is still popular today. Your city is interested in
creating its own bike sharing program. You have been tasked to see how the first 2 years went in DC to
anticipate any factors that might affect usability such as weather, seasons, or holidays.

A few questions have been provided to help guide your thoughts in this exercise.

### EDA

1. What hours are these bikes most popular with casual riders?
- What about registered riders?

1. What daily trends do you see between casual riders and registered riders from 2011-2012.
- Use `Dteday` and drill down.

### Basic Calculation:

1. Do holidays impact casual rentals?
1. What about registered rentals?
- Rename `Holidays` from 0 and 1 to “Holiday” and “Non-Holiday” using a calculated field.

1. Does the season increase or decrease usage?
- How does that compare with weather?

1. Use a calculation to rename the `Seasons` that is more useful than a number.
- 1 = Spring
- 2 = Summer
- 3 = Fall
- 4 = Winter

1. Use a calculation to rename the `Weather` so that it is useful to us humans.
- 1 = Clear
- 2 = Fog or Mist
- 3 = Light precipitation
- 4 = Heavy precipitation

1. Does the average temp (°F) impact all riders? 1. Use calculations to convert the `Temp` from a “Normalized” scale of 0-1, to °C then finally to °F.
- Convert from 0-1 to Celsius using the following formula: **temp = 47 * temp - 8**
- [Formula source](https://www.andrew.cmu.edu/user/achoulde/94842/homework/homework5.html).
- Quick Check: The average temp of Jan 1, 2011 is 46.72°F and the average temp of Feb 1, 2011 is 33.86°F.


### Table Calculation:

1. How many total bike rentals occurred in the city between Jan 2011 to Dec 2012?
- What are the running totals of bike rides between 2011-2012?
- Hint: You can use a quick calculation for this.

### Parameter:

1. Duplicate EDA question 1 and create a parameter that will allow a user to choose between hourly casual or registered user usage.
- Hint: You are changing a field with a parameter.

### Dashboard & Finesse:

1. Make sure your final dashboard has:
- Informative titles, axes, and other text elements.

1. Before submitting your work, reflect on these questions. You don't need to submit any answers for these questions.
- Would there be any other data that you wish you had as you worked with this data?
- Are you happy with your data visualizations?
- Is there anything you would like to learn more about for your future projects?

## Submitting Your Work

When finished make sure to save and publish your work to your Tableau Public account. Copy the URL to your published Tableau project and paste it into the submission box in
Canvas for **Exercises: Visualization with Tableau Part 3** and click *Submit*.
12 changes: 12 additions & 0 deletions content/tableau-part-three/next-steps.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
+++
title = "Next Steps"
date = 2021-10-01T09:28:27-05:00
draft = false
weight = 4
+++

You are now ready to move into Tableau Part Four. If you would like to further explore content related to calculated fields, parameters, or relationships, you can find some of our favorite resources below.

1. [Tableau Documentation: Getting Started with Calculations in Tableau](https://help.tableau.com/current/pro/desktop/en-us/calculations_calculatedfields_create.htm)
1. [Tableau Documentation: Create Parameters](https://help.tableau.com/current/pro/desktop/en-us/parameters_create.htm)
1. [Tableau Documentation: Relate Your Data](https://help.tableau.com/current/pro/desktop/en-us/relate_tables.htm)
12 changes: 12 additions & 0 deletions content/tableau-part-three/reading/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
+++
title = "Reading"
date = 2024-05-28T13:45:19-05:00
draft = false
weight = 1
+++

## Reading Content

{{% children %}}


128 changes: 128 additions & 0 deletions content/tableau-part-three/reading/calculations/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
+++
title = "Calculations"
date = 2024-05-28T13:45:19-05:00
draft = false
weight = 1
+++

## Calculations

Applying calculations to your visualization helps further customize, filter, and aggregate data. Calculations can be something as simple as applying an `AVG` or any other aggregate function.

Regardless of what type of calculation you apply to your visualization, we consider the result a **calculated field**.

When a new calculation is created, a new pill will be added to your data pane under the name you provided the calculation. We will cover **basic calculations** and **table calculations** below.

## Basic Calculations

Basic calculations in Tableau revolve around using arithmetic operators and functions to manipulate and transform your data as you see fit. Calculations can be applied to an individual field or multiple fields, allowing you to create new extracted fields based on your analysis requirements.

Take a look at the example below:

{{% notice blue Example "rocket" %}}
```python
AVG([Transaction Total])
```

This would provide you a calculated field pill that would store the `AVG` of the `Transaction Total` field.
{{% /notice %}}

### Calculation Components

When you are creating a new calculation there are some multiple components to familiarize yourself with:
1. Fields: You are able to include existing fields from your data inside of a calculation like in the example above referencing the `Transaction Total` field.
1. Operators: (`>`, `<`, `=`, `>=`, `<=` etc..)
1. Literal expressions: Specific values (`23`, `"String"`, `true`, `false`, null, `#Date`)
1. Functions: Tableau provides a numerous amount of functions that you can apply within your calculated fields. The functions available include aggregate functions, number functions, logical functions, etc..

{{% notice blue Note "rocket" %}}
Tableau documentation provides an exhaustive list available functions included that you will be able to make use of. You can find a list of all [functions included here](https://help.tableau.com/current/pro/desktop/en-us/functions_all_categories.htm).
{{% /notice %}}

You can select or include a function from a list during the process of creating a new calculated field.

1. Click on `Analysis`.
1. Then click on `Create Calculated Field...`.
1. Click on the arrow to expand the list of available functions.

![Creation of a new calculated field within Tableau public, expanding the list of available functions](pictures/tableau-available-functions.png?classes=border)

## Table Calculations

Table calculations are considered any manipulation or transformation applied to any value that is already visualized. These calculations allow you to perform analytics and add context to your visualizations by comparing individual values to the overall data set or a specific partition. Table calculations are powerful because they can be used to calculate running totals, moving averages, percentages of totals, and much more.

### Partitioning Fields

When working with table calculations, you can optionally specify one or more **partitioning fields**. Partitioning fields are used to define subsets or partitions of your data, and the table calculation will be performed independently for each partition.

{{% notice blue Example "rocket" %}}
If you have a sales data set with fields like Region, Product, and Sales, you could partition your table calculation by Region to calculate running totals or percentages of totals for each region independently.

This allows you to analyze and compare values within specific partitions of your data.
{{% /notice %}}

### Addressing Fields

In addition to partitioning fields, table calculations also require you to specify one or more **addressing fields**. Addressing fields determine the order or direction in which the calculation is performed within each partition.

{{% notice blue Example "rocket" %}}
If you have a time-based data set with a `Date` field, you could use `Date` as the addressing field to calculate a running total or moving average over time. The addressing field dictates the order in which the calculation is applied to the values within each partition.

By combining partitioning fields and addressing fields, you can create highly customized and insightful table calculations that provide valuable context and enable deeper analysis of your data.
{{% /notice %}}

<!-- TODO: Add image below of creating table calculation -->

## Conditional Statements

You can utilize a few types of conditional statements within calculated fields. The three types of conditional statements we will cover are `IF` and `IIF` and `CASE` statements.

{{% notice blue Note "rocket" %}}
Each conditional statement has it's own use cases. When comparing the `IIF` to the `IF` statement, the `IIF` statement allows you to specify how unknown values are treated, otherwise they are quite similar.

The `CASE` statement is especially useful if you would like to rename values within a given field. Similar to `IF` statements `CASE` statements are often used to format and filter data. Let's look at a few examples below.
{{% /notice %}}

{{% notice blue Example %}}
`IF` statement syntax:

```python
IF some condition
THEN do this
## ELSE statement is optional
ELSE do this
END
```
{{% /notice %}}

{{% notice blue Example %}}
`IIF` statement syntax

```console
IIF (some condition, do this if true, else this if false, handle unknown)
```
{{% /notice %}}

{{% notice blue Example "rocket" %}}
You have a field named `Operating Systems` that contains the three major types of operating systems (`Linux`, `Windows`, and `MacOS`) but they were represented by numbers within the field instead of the string values. You could create a calculated field like the one below to provide more descript value names:

```python
CASE[Operating Systems]
WHEN 1 THEN "Linux"
WHEN 2 THEN "Windows"
WHEN 3 THEN "MacOs"
END
```
{{% /notice %}}

## Check Your Understanding

{{% notice green Question "rocket" %}}
Which of the following is NOT one of the four basic components of a Tableau calculation?

1. Functions
1. Level of Detail
1. Fields
1. Operations
<!-- Solution: Level of Detail -->
{{% /notice %}}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
74 changes: 74 additions & 0 deletions content/tableau-part-three/reading/parameters/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
+++
title = "Parameters"
date = 2024-05-28T13:45:19-05:00
draft = false
weight = 2
+++

## Parameters

**Parameters** allow for more fine-tuned control over calculations that you would like to apply to any part of your visualization. For example, if you would like to divide multiple measures by a specific amount, you can create a new calculation and then attach or include your parameter within.

One of the major benefits is that you can change your parameter value on the fly so that your calculations will be updated dynamically wherever they exist. Only having to change one value instead of many to view a different result is extremely convenient.

On its own, a parameter will not have an effect on the visualization because at its core it is a variable that is referenced inside of a calculation, filter, or reference line.

### Creating a Parameter

To create a parameter in Tableau:
1. Select the arrow icon within the Data pane which opens a dropdown.

![Create a new paramater using Tableau public](pictures/create-parameter.png?classes=border)

1. Click on `Create Parameter...`
- this will open up a menu allowing you to create a brand new parameter.

![Create a parameter in Tableau menu](pictures/parameter-menu.png?classes=border)

### Parameter Settings
When creating a parameter, you can define several properties:

1. `Name`: Provide a descriptive name for your parameter, which will be used to reference it in calculations and filters.
1. `Data Type`: Make sure to select the correct data type for your use case. Usually this is in reference to the field that you will be using within the parameter.
1. `Current value`: Initial or default value.
1. `Value when workbook opens`: What value should be displayed when the workbook is first opened.
1. `Allowable values`: Select either All values, a list of values, or a range of values to select from.
1. `Value and Display As`: You can changes how each value is displayed within the visualization itself with the display as option.
1. `Add values from`: Select where you want to add values from for the parameter itself, this is usually a field from your data.

### Using Parameters in Calculations
After creating a parameter, you can reference it in your calculations by using the parameter name enclosed in square brackets:

{{% notice blue Example "rocket" %}}
If you have a parameter called `Tax Rate`, you can create a calculated field like the one below:

```console
[transaction_total] * (1 - [Tax Rate])
```

This will apply the `Tax Rate` parameter to your the transaction_total field data.
{{% /notice %}}

### Using Parameters in Filters

Parameters can also be used in filters to dynamically filter your data based on the parameter's value. When creating a new filter, you can select from a list of available parameters or create a new one within the `Top/Bottom` section as shown in the image below:

![Select a parameter or create a new one within the Top/Bottom section of adding a filter](pictures/filter-parameter.png?classes=border)

## Check Your Understanding

{{% notice green Question %}}
Parameters must be incorporated into something else such as a filter, reference line, or calculation field in order to be useful.

1. `True`
1. `False`
{{% /notice %}}

{{% notice green Question "rocket" %}}
In order to use a parameter within a calculated field you must reference it with:

1. parenthesis: `()`
1. curly brackets: `{}`
1. square brackets": `[]`
1. double quotes: `""`
{{% /notice %}}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions content/tableau-part-three/reading/relationships/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
+++
title = "Relationships"
date = 2024-05-28T13:45:19-05:00
draft = false
weight = 3
+++

Tableau allows you to create **relationships** between data sources. The relationship itself is based on a column(s) that the two tables you are trying to relate. A relationship must have at least one matching pair of fields in order to be created, meaning they must be of the same data type.

One of the great things about relationships with Tableau is that you do not need to specify the join type for the relationship, Tableau takes care of that query behind the scenes for you amongst other things:

1. Aggregation: When using fields from related tables, Tableau will automatically aggregate data based on the relationships created.
1. Logical Data Model Creation: Tableau also builds a logical data model when a relationship is made. The model itself is a represenation of each individual field you associated with each other for the relationship.
1. Integration: Once the relationship is established, fields from both tables will be available when creating a new worksheet. Tableau will automatically use the relationship to combine and display the data correctly.

## Creating a Relationship

In order to create a new relationship you can simply existing data sources onto the canvas and select the appropriate columns to relate.

1. In the example below, we initially connected to the `cleaning-data-practice` data source which serves as the **root table** for building the relationship. After creating an additional connection to the `transaction-data` data source, dragging it only the canvas alongside `cleaning-data-practice` created a relationship between the two.

![Create a new relationship by dragging an additional table onto the canvas](pictures/create-relationship.png?classes=border)

2. Initially, we received an error message notifying us that matching fields need to be selected in order to create the relationship

![Relationship displays as invalid because the fields do not match](pictures/invalid-relationship.png?classes=border)


3. Selecting the `transaction_total` from each table cleared the error message allowing us to establish the relationship using the matching fields of data.

![Update the relationship so that the transaction total column is selected from each table](pictures/valid-relationship.png?classes=border)

4. As mentioned above, you can add as many fields as you would like to the relationship as long as you have fields that allow for it.

![Adding a secondary matching field to the relationship between the cleaning-data-practice and transaction-data tables](pictures/add-more-fields.png?classes=border)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit c1a0de0

Please sign in to comment.