Tableau Online Guide – BMC Software | Blogs https://s7280.pcdn.co Wed, 09 Dec 2020 09:49:11 +0000 en-US hourly 1 https://s7280.pcdn.co/wp-content/uploads/2016/04/bmc_favicon-300x300-36x36.png Tableau Online Guide – BMC Software | Blogs https://s7280.pcdn.co 32 32 How To Create a Heat Map Chart in Tableau Online https://s7280.pcdn.co/tableau-heat-map-chart/ Mon, 11 May 2020 00:00:48 +0000 https://www.bmc.com/blogs/?p=17313 In the chart below, the data points are too close together—a common problem that prevents you from reading the chart and gaining any intelligent meaning. A heat map solves this problem by adding color to illustrate where individual points overlap. The color changes or intensifies as the number of data points in a region increases. […]]]>

In the chart below, the data points are too close together—a common problem that prevents you from reading the chart and gaining any intelligent meaning.

A heat map solves this problem by adding color to illustrate where individual points overlap. The color changes or intensifies as the number of data points in a region increases. The heat map also lets us put an additional metric on the otherwise 2-dimensional chart.

So, let’s look at how you can create a heat map in your Tableau Online chart.

Tableau Online chart

(This article is part of our Tableau Online Guide. Use the right-hand menu to navigate.)

Creating a heat map

To make a simple heat map, open Tableau Online and create a new worksheet. Choose the Superstore Datasource, which is included with Tableau.

new worksheet

Now go to the worksheet editor:

Worksheet editor

We want to figure out which sales offices are producing the highest sales and profits. We need to look at both sales and profits together. This is because, for examples, sales can be high while profits low, which may indicate that the sales office is giving too many discounts or operating at too high a cost.

So, we plot three metrics:

  • Average sales
  • Average profit
  • Office location (city)

Drag sales to columns and profit to rows. Change SUM() to AVE(Sales) and AVE(profit). Then drag city onto the detail mark. Then change the chart type to density.

We then get this heat map:

Heatmap

Of course, the data is still too close together to read all the data points. But that is not the point in this exercise: if we wanted to read individual metrics, we could have made a cross table with just text. Instead we use the heat map to identify both outliers as well as the profitability at which most offices are operating.

To drill in to read single office details, click on the chart to get the data point located there.

Chart

To zoom into an area, thus removing the outliers, we can adjust the axes by setting the axis range to fixed and entering a value there.

Heatmap settings

That results in a chart zoomed into a closer level like this. Now we can click on the data points in that zoomed-in region to more closely inspect that tightly packed region.

Heatmap Zoomed in region

We could also drop the cities, only look at the states, but then there is less need for a heat map—that chart would not be as dense.

Heatmap Results

]]>
How To Make a Box and Whisker Plot in Tableau Online https://www.bmc.com/blogs/tableau-box-whisker-plot/ Wed, 06 May 2020 09:39:12 +0000 https://www.bmc.com/blogs/?p=17204 A box and whisker plot provide more statistical information on a single chart than you would normally be able to fit. It lets you see at a glance the median and the range of data points that lie within each quartile. (This article is part of our Tableau Online Guide. Use the right-hand menu to […]]]>

A box and whisker plot provide more statistical information on a single chart than you would normally be able to fit. It lets you see at a glance the median and the range of data points that lie within each quartile.

(This article is part of our Tableau Online Guide. Use the right-hand menu to navigate.)

Median definition

The median is not the average. Median is defined as the point that divides the number of data points in half. That means the value where 50% of the points are above that value and 50% are below. Quartiles divide that range of data into four equal ranges. Those quartiles are then 1st, 2nd, 3rd, and 4th.

Whiskers and hinges in Tableau

Tableau has their own names for these quartiles: hinges and whiskers. The whiskers are the ends of the range. The hinges are bottom and top of 2nd and 3rd quartiles respectively.

Tableau draws a box around the 2nd and 3th quartile, hence the name box and whisker chart.

Box and Whisker Chart Illustrated

For example, if we look at the range of stock prices for three stocks over a certain period of time we get this box and whisker plot:

The stock on the left is Johnson & Johnson. Over this time period, the price has ranged from $29 to $151.60. The median price is $92.50 because half of the prices range between the lower and upper hinges, which are the 2nd and third quartiles. The box colored grey is the 2nd quartile. Light grey is the third.

How are box and whisker charts useful?

The box and whisker chart conveys in one glance more information than you’d otherwise get from a bar chart. That is useful when, for example, you need to print these charts, showing them to someone or using them as part of a non-digital presentation.

The usual way that online charts provide additional information is by popping up a text box with extra metrics when you hover the mouse over one spot—which you obviously cannot do on paper.

How to create a box and whisker chart

Download a source of stock prices and connect that to Tableau. You can use this data, which I assembled from Yahoo Finance and Stockpup and then loaded into a database.

Now you put the stock symbol on the columns and the closing stock price on the row. Change the close to a dimension so that it uses individual daily stock prices and does not average or sum.

Drag the stock symbol onto the detail mark. Pick the whisker and bar chart type. If that chart is greyed out then clear the chart and draw symbol and close into place, which will put sum(close). Charts are greyed out when they don’t logically fit the data presented to them.

When you change sum(close) to close—by changing it to a dimension—the whisker and box plot options is greyed out. I am not sure why that it the case as the chart would work for both metrics, but that’s how Tableau works.

Now the worksheet should look like this:

Zooming in close we can see the popup text box that gives you the ranges. (Here you see it exactly. You can also estimate it from the vertical axis.)

Check your work

You should always check your work to alleviate any doubts you have about these numbers by plotting each of these stock prices over time. You check your work by presenting the same information in another format. Whenever you do data charting, with Tableau or any type of charting software, you should perform checking like these to find and resolve any errors.

Plot multiple lines

Here, I make a union as it’s the easiest way to put multiple lines on a line chart. So first I make three views:

create view sbux as select * from prices where symbol = ‘SBUX’;
create view jnj as select * from prices where symbol = ‘JNJ’;
create view dis as select * from prices where symbol = ‘DIS’;

Then create a Union datasource in Tableau, adding each view to the union:

Now plot stock price by quarter against the average closing price. Don’t plot the exact date as there will be too many data points to easily read.

As we see, J&J has never exceeded $151, and the highest monthly price was near that amount. So, this gives us more confidence in the box and whisker chart we created above. If you want to check the daily prices, you’ll know for certain. The top prices should be $151.

Make a dashboard

You need to make a dashboard so that users can both get a larger view of the chart plus not be able to make changes to your worksheet. So, click on the dashboard icon:

Now drag the worksheet you just made onto the dashboard:

You can add both charts you just made onto the dashboard as well:

Close the worksheet

Finally, it’s sometimes difficult to figure out how to close the worksheet and get back to the user-friendly landing page from where users can see their favorites dashboards. To close your worksheet, use this X:

Explore your charts

From the landing page, you can use the Explore button to open a folder and flip through the charts in each, viewing whichever ones you want:

In the default folder we have these folders:

And these charts in earnings and dividends:

The star lets the user mark their favorite which will show up when they first open Tableau.

Click on the dashboard that we just made and here it is. In addition to being larger it also adds the ability to download the chart as an image file, which is useful.

]]>
Tableau Online: Plotting Multiple Axes on the Vertical Axis, Pt. 2 https://www.bmc.com/blogs/tableau-plot-multiple-axes-part-2/ Thu, 23 Apr 2020 00:00:28 +0000 https://www.bmc.com/blogs/?p=17086 Here we show how to plot more than one metric on a single vertical axis in Tableau Online. Metrics are called Pills in Tableau, since they are shaped like a pill. (This article is part of our Tableau Online Guide. Use the right-hand menu to navigate.) The problem For the beginner, Tableau Online is frustrating […]]]>

Here we show how to plot more than one metric on a single vertical axis in Tableau Online. Metrics are called Pills in Tableau, since they are shaped like a pill.

(This article is part of our Tableau Online Guide. Use the right-hand menu to navigate.)

The problem

For the beginner, Tableau Online is frustrating because, when you put two metrics on the rows (horizontal), it draws two charts as the default behavior. Users of Microsoft Excel are used to Excel doing the desired behavior, plotting multiple axes, automatically.

In Part 1 of this tutorial, we did that using a union. Here we do that by taking two data points from a single view. We’ll create charts with:

Generate your data

You can run this Python code to create some data and then run this SQL command to add a revenue column. Or just pick any data that you have and follow these general instructions.

create view revenue as select salesdate, product, quantity, quantity * random() * 10 as revenue from sales;

Plot two data points on left vertical axis

Create a new data source.

Drag the Salesdate to Columns and then change the date from YEAR() to exact date.

This next step is not exactly intuitive. Drag Measure Names onto the Color Mark. Drag the Measure Values to Rows. This creates a legend to the right for each metric and plot each metric on the chart. (That is the frustrating part for beginners as if you drag each metrics onto Rows it makes a separate chart for each metrics.)

You’ll also want to remove SUM(Number of Records) as that’s not too useful, but Tableau Online adds it to the chart automatically. So, scroll down and find it and remove it from here:

The chart now looks like this:

Zoom in for a closer view:

Plot two data points on dual axis

The chart above looks OK. You could change the label Value to Revenue/Quantity. But let’s use another technique and plot one metric on the left axis and the other on the right axis.

So, instead of using Measure Values drag Revenue and Quantity onto Rows.

Tableau makes two charts. So click Sum(Revenue) and then select Dual Axis to make one instead.

The resulting chart is a bit crowded:

So, edit the quantity axis to force values to a range that does not overlap with the revenue range.

Set a fixed range.

Now it’s easier to read:

Zoom in for a closer view.

]]>
Tableau Online: Plotting Multiple Axes on the Vertical Axis https://www.bmc.com/blogs/tableau-plot-multiple-axes/ Thu, 09 Apr 2020 00:00:38 +0000 https://www.bmc.com/blogs/?p=16910 Look on Stack Overflow for how to plot multiple lines on a line chart in Tableau Online and you will turn away frustrated. Perhaps you can do two. Perhaps you can do three, if you also use the right-hand axis. Most instructions you find are for Tableau Desktop. But Salesforce has bought Tableau, so online […]]]>

Look on Stack Overflow for how to plot multiple lines on a line chart in Tableau Online and you will turn away frustrated. Perhaps you can do two. Perhaps you can do three, if you also use the right-hand axis. Most instructions you find are for Tableau Desktop. But Salesforce has bought Tableau, so online is where you need.

In this article, I show how to plot as many lines you want on a Tableau chart.

(This is part of our series on Tableau and assumes you have a basic understanding of the program. If not, you can start with Tableau: Getting Started with Real Examples or Tableau for Finance: How To Join Tables, Write Calculations, and Analyze Finances, among others.)

(This article is part of our Tableau Online Guide. Use the right-hand menu to navigate.)

Use case: Sales by employee by date

Look at this chart. This is three dimensions. If you were to take the normal approach to plotting this data, it would create separate charts for each employee. That’s not a good way to show how one metric relates to another, since it’s on a different chart. Stacking all the data onto one chart is easier to see.

To follow this tutorial, download and run this Python code. Then, create this table:

create table sales (
salesperson varchar(50),
product varchar(50),
quantity numeric,
salesdate date);

Next, create a separate view for each of the salespeople (they are listed in the code) like this:

create view bob as select * from sales where salesperson = 'Bob';

Now create a union in the data source screen in the worksheet. Drop each view onto the union. A union is all of the data sets (views in this case) added together.

Now create the worksheet:

Change the saledate to group by month:

Drop the table name on the color mark.

This assigns a different color to each view and creates a legend to the right.

Select Show mark labels so you can see the numbers.

Here is a closer view:

And zooming in further:

Creating different charts in Tableau

Now we can play around and select the Show me tab on the right and create different kinds of charts.

We need to have one or more dimensions and one or more measures. Remember dimensions are items you can do math calculations on (e.g., sales), and measures you cannot (e.g., table name and dates).

To remove decimal points, do this:

Here is a different chart:

This is your data in a text table:

The same, but with the darling colors of a heat map (This is not a heat map, not exactly.)

]]>
Creating a Tableau Text Table with Measures and Dimensions https://www.bmc.com/blogs/tableau-text-table/ Thu, 02 Apr 2020 00:00:21 +0000 https://www.bmc.com/blogs/?p=16867 Part of our ongoing Tableau series, this article explains how to create a text table. You can think of a text table in Tableau as the same as a pivot table in Excel. It’s a table, not a chart, with one or more values in the rows and one or more values in the columns. […]]]>

Part of our ongoing Tableau series, this article explains how to create a text table.

You can think of a text table in Tableau as the same as a pivot table in Excel. It’s a table, not a chart, with one or more values in the rows and one or more values in the columns. The easiest way to picture a text table is to think of sales or expenses by date. In this example, we will use expenses.

(This article is part of our Tableau Online Guide. Use the right-hand menu to navigate.)

Putting data in Tableau

If you’re new to Tableau, see our starter article Tableau: Getting Started with Real Examples. For the data, I’m using my credit card statements. You can easily download your credit card into one of the supported data sources, like PostgreSQL.

Defining measures and dimensions

First, we need to understand two concepts: measures and dimensions. There are long definitions in various tutorials that try to explain what dimensions and measures are. But here’s a really easy one:

  • A measure is a number, which is anything you can do math on. A measure includes expenses, sales, etc.
  • A dimension is anything that is not a number, such as dates, or text fields like category.

In Tableau, fields are grouped by dimension and measures on the left-hand side of the worksheet editor, like this:

Examples of text tables

By default, Tableau is designed to work with sums, which they call aggregation. So, a text table will by default display aggregated data.

Here are some examples of what your text table can show:

Expenses by category

This table has one dimension, category, and one measure, expenses.

Expenses by date and category

In this table, we add a second dimension: date. If this was a chart you would say that a dimension is an axis, like the XY-axis in a scatter chart.

Expenses by date, category, and description

Here, we’ll add a third dimension: payee. You could use any other description, too.

(Note: If this was a chart it would be a three-dimensional chart. Because those are hard to visualize, it’s easier to use a text table. Of course, there are ways to see more than one dimension on a chart by, for example, adding more than one line to a line chart and making use of both the left and right-hand axes of a chart.)

We put dimensions on the row and columns. If you were to flip the rows and columns of the text table above, you get two columns of columns (category and description) by month.

This makes sense if you think of the idea of a column as being all the fields you have added to the column line at the top. A programmer would call this (category, description) a tuple.

You can also think of rows the same way, as being a collection of whatever you assign to the row line. For example, above each row contains both category and description or (category, description) pairs.

Adding measures to the text table

When you first pick a row and column dimension, Tableau does not know what value you want to put at each row, column intersection. So, it populates each cell with abc. To fix that, we add a measure to the table. You do that by dropping it onto the marks tab and then selecting text, line, bar, or however you want to display this. We use text for a text table.

First note that we change date from year(Postdate) to Month(Postdate) as Tableau, by default, usually assumes we want to sum values by year. That is, aggregation is its initial position, and for whatever reason it picks year first.

To put a number (dimension) onto the table, drag a dimension, in this case amount, onto the text mark. Since Tableau assumes aggregation it will add sum() to amount to give us expenses by month.

Then the worksheet fills in the numbers:

]]>
Tableau: Join Tables on Calculated Fields and Create Crosstab Tables https://www.bmc.com/blogs/tableau-create-crosstab-tables/ Wed, 25 Mar 2020 00:00:46 +0000 https://www.bmc.com/blogs/?p=16780 This is part of our ongoing series on Tableau. In this article, I’ll show how to join Tableau tables on a calculated field and how to create a table text, which is also known as a crosstab table. (This article is part of our Tableau Online Guide. Use the right-hand menu to navigate.) Getting the […]]]>

This is part of our ongoing series on Tableau. In this article, I’ll show how to join Tableau tables on a calculated field and how to create a table text, which is also known as a crosstab table.

(This article is part of our Tableau Online Guide. Use the right-hand menu to navigate.)

Getting the data for Tableau

To illustrate a variety of Tableau functions, we’ll continue looking at the same three stocks: Starbucks (SBUX), Johnson & Johnson (JNJ), and Disney (DIS).

Download the data we are using from here. There are three tables in that zip file: price, earnings, and dividends. We will look at price and earnings. Set a filter to extract only SBUX.

A note on the terms:

  • Price is the stock price.
  • Earnings are the quarterly filings.

How to join Tableau tables

For whatever reason, the filing dates for Starbucks (SBUX) earnings always fall on a Sunday. We need to do some math to change that to Monday, so that we can match up the stock price with earnings. (The stock market is closed on Sundays.)

So, we’ll create a calculated field to join the two tables, which adds a new field to the earnings table that will match a field in the price table. (Of course, that means we will lose data for those Mondays which are a holiday. You could, as an exercise, try to fix that.)

The two tables have these common elements:

prices table Symbol Date
earnings table Symbol Quarterend

We calculate:

DATE([Quarterend]) + 1

And use that as our join criteria.

So, we add a calculated field to our join criteria.

We will make an inner join, which will match up records with the same stock symbol with the stock price date and the earnings date on the Monday after the filing.

So, the number of records we will have will be equal to the number of quarterly filings. Our data is from 2010 to 2018.

Click below to add this calculation on the earnings column.

This takes the Quarterend string, converts it to a date then adds 1 to it.

Then the join criteria will look like this:

How to create a crosstab table

In the worksheet view you see the both tables: earnings and prices. The easiest way to make a crosstab table is to drag measure values onto the Text mark.

Then drag Measure Names to Columns.

Then drag Quarterend date to Rows, since we want financial data by date. Format the date show that is shows the full date. Tableau tends to collapse that to year, as it assumes we want to do aggregation. (That’s logical since, in most cases, you want a report to sum data. In this case, we want the report to show all the data.)

Add the Measure Values to the filter tab and then deselect fields until you have what you want to see. For financial analysis that would be the balance sheet values assets, liabilities, and cash and profit and loss value earnings.

Tableau always assumes we want to sum values. For the sake of simplicity, we will leave it at that, because we have only 1 record per date. So, the sum and individual values are the same.

Now the worksheet shows these Measure Values. If we had not dropped Measure Values on the Text Mark it would show abc in every field. Not sure why that is; it just behaves that way.

Our complete report of stock price on earnings data looks like this:

]]>
Using Tableau to Track Coronavirus https://www.bmc.com/blogs/tableau-coronavirus/ Mon, 16 Mar 2020 11:54:25 +0000 https://www.bmc.com/blogs/?p=16692 Today, when all any of us can do is watch Coronavirus news, we show how to map the coronavirus using Tableau. We use data gathered by the John Hopkins University School of Engineering.  They have built this dashboard which has gained a wide following among news outlets around the world. (This article is part of […]]]>

Today, when all any of us can do is watch Coronavirus news, we show how to map the coronavirus using Tableau.

We use data gathered by the John Hopkins University School of Engineering.  They have built this dashboard which has gained a wide following among news outlets around the world.

(This article is part of our Tableau Online Guide. Use the right-hand menu to navigate.)

John Hopkins Coronavirus Github

John Hopkins uploads that data to their github repository here every day.  John Hopkins as of March 1st started adding longitude and latitude to the data feed.

Tableau is well-suited to work with geographical data.  We can upload it to Tableau and quickly turn it into the same kind of chart that John Hopkins has built. Then we can build a chart that looks much like what John Hopkins has built. Tableau knows that we want virus count by country.  It’s fairly effortless to produce this kind of chart.

Our chart will look like this:

 

Download the Virus Data and Upload to a Database

To start, download the latest data:

wget https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_daily_reports/03-16-2020.csv

We are using PostgreSQL. You can use any of the databases that Tableau supports.

From the psql shell create a database, then create the coronavirusgeo database;

create table coronavirusgeo
( provinceState VARCHAR(50),
CountryRegion VARCHAR(50),
LastUpdate date,
Confirmed numeric,
Deaths numeric,
Recovered numeric,
Latitude numeric,
Longitude numeric);

Now load that data from the csv file into PostgreSQL:

COPY coronavirusgeo FROM '/home/ubuntu/Downloads/03-16-2020.csv' DELIMITER ',' CSV HEADER;

You do all that as the admin user. But you don’t want to use the admin account to connect to your PostgreSQL server from Tableau. So grant a designated user access to that database and table.

grant all privileges on database virus to walker;
grant all privileges on table coronavirusgeo to walker;

Connect the Database To Tableau and Create the Worldmap Chart

Connect the PostgreSQL database to Tableau. Then start adding fields on the chart.
If you uploaded more than one daily report then you need to set a filter to select just that one day.
Set the filter 3/16/2020:

Then drag the fields longitude and lattitude to the columns and rows. Tableau will recognize these fields are in your data when you first connect to the coronavirus table and will assume that you want to map this data.

If it has not already done so, kick the World View chart type:

Add the fields below to the chart and change deaths and confirmed to dimension from sum.

Now you can zoom in on any part of the world and take a look. It displays numbers for the area on which you click.

]]>
Tableau: Calculate Covariance and Correlation Between Stock Prices and Earnings https://www.bmc.com/blogs/tableau-covariance-correlation/ Thu, 12 Mar 2020 00:00:49 +0000 https://www.bmc.com/blogs/?p=16626 Continuing our series on Tableau, here we explore two important components: how to calculate covariance and correlation and how to use the trend line. We want to answer: “To what extent is the stock price positively correlated with earning?” That answer, as most people who follow the stock market know, is somewhat. Let’s get started. […]]]>

Continuing our series on Tableau, here we explore two important components: how to calculate covariance and correlation and how to use the trend line.

We want to answer: “To what extent is the stock price positively correlated with earning?” That answer, as most people who follow the stock market know, is somewhat. Let’s get started.

(This article is part of our Tableau Online Guide. Use the right-hand menu to navigate.)

Data for Tableau

We will use the same financial data that we used in our last Tableau tutorial: the stock prices, earnings, and dividends for Starbucks, Johnson & Johnson, and Disney. We will pick just one company, the J&J stock price. To simplify things (meaning: avoid having to join two tables and collapse one of them), we will get the stock prices from their quarterly reports instead of using the stock price data.

Understanding correlation and covariance

Correlation means a change in one component or area causes an equal increase in the other. The change may be positive or negative. Covariance measures how those variables change together, but it can scale to any number, making it difficult to understand.

Here we use stock price and earnings. We create a line chart of the quarter ending date against the price column. The correlation is shown to the left. This is the CORR function. We say that two items are positively correlated when this value is 1.

The value in our graph is 0.65, which indicates some but not very strong correlation. It would not make sense to plot the correlation value across the whole chart, since it’s a single number. So, Tableau shows the one number.

Plotting and using a trend line

Basically, a trend line will reaffirm what we observation from the correlation value. Think of this line in terms of linear regression: It is the line that most neatly slices the data points down the middle.

To add a trend line to your chart, pick the trend line from the worksheet design screen on the analytics tab. This adds a dashed line between the points on the plot line.

Since this is a XY plot (i.e., the line y = mx + b), if you hover the mouse over the trend line, Tableau shows you:

In this case:

  • y (price) is the dependent value
  • Earnings is the independent value
  • 9 is the value b
  • The y intercept, the point where x crosses the vertical (y) axis
  • m is the slope of the line y = mx + b or 0.0000000187
  • Price = (0.0000000187 * earnings) + 32.9

There are various types of trend lines. This one shows additional information:

  • R-squared = 0.608871 means the variation in price given variance in the earnings. As you can see it’s almost the same value as the correlation—which is what we would expect.
  • P-value < 0.0001 is a test of the null hypotheses. It tests whether there is no relationship between price and earnings. Clearly, they are related, as the P-value is a small number.

Disabling aggregation

Tableau always assumes you want to do aggregation. So, it adds the function SUM() to add numeric values and uses the YEAR() function on dates.

This is annoying behavior when you want to do a scatter or line chart. To use individual values and not the sum, elect the value dimension when you click on a number, like price.

The same is true with the date. Pick the exact date so it won’t use the YEAR function, although it will still scale the chart so it’s easy to read. You can still pick year anyway, or year with month to be more specific.

Calculating correlation

We calculate correlation by clicking Create Calculated field. The formula is below.

The curly braces {} means to make it a table calculation as opposed to running the calculation only against what is shown on the chart. That’s what we need to do, as Tableau automatically scales charts to make the data fit on the screen thus skipping over some data points.

]]>
Tableau for Finance: How To Join Tables, Write Calculations, and Analyze Finances https://www.bmc.com/blogs/tableau-join-tables-write-calculations/ Tue, 10 Mar 2020 13:30:59 +0000 https://www.bmc.com/blogs/?p=16622 This is the fourth post in our series on Tableau. For the next few blog posts, I’m going to illustrate certain Tableau concepts. For the data, I’m using stock price, earnings, and dividend information from Disney, Starbucks, and Johnson & Johnson. In this article, I will illustrate how to join tables, use right and left […]]]>

This is the fourth post in our series on Tableau. For the next few blog posts, I’m going to illustrate certain Tableau concepts. For the data, I’m using stock price, earnings, and dividend information from Disney, Starbucks, and Johnson & Johnson.

In this article, I will illustrate how to join tables, use right and left joins, reverse mistakes, and use statistical functions to find correlation between variables. We’ll use these functions and analytics to answer these questions:

  • To what extent do stock prices reflect cash flow and earnings?
  • Are dividends related to cash flow or earnings?

(This article is part of our Tableau Online Guide. Use the right-hand menu to navigate.)

Setting up Tableau

If you’re new to Tableau, you can see our previous articles that help you get started with basic datasets and examples. Previous articles include:

Download the data

To start, you’ll need data. To get the data I use, simply do what I did: download from Stockpup and Yahoo Finance and clean it up a little. The earnings data for all three companies is from 1999. Stock prices and dividends are from 2010 to 2018.

Download the data here. Next, store the companies’ earnings, dividends, and stock data in any database you like, as long as it is supported by PostgreSQL. (We use PostgreSQL.)

Creating tables for Tableau

Here are the steps for creating your tables of data:

  • Use the below commands to create the tables.
  • Upload your tables to PostgreSQL.
  • Connect those data sources to Tableau using the procedure we previously outlined.
create table earnings (
Symbol VARCHAR(50),
Quarterend date,
Shares bigint,
Sharessplitadjusted bigint,
Splitfactor bigint,
Assets bigint,
CurrentAssets bigint,
Liabilities bigint,
CurrentLiabilities bigint,
Shareholdersequity bigint,
Noncontrollinginterest bigint,
Preferredequity bigint,
Goodwillintangibles bigint,
Longtermdebt bigint,
Revenue bigint,
Earnings bigint,
Earningsavailableforcommonstockholders bigint,
EPSbasic float,
EPSdiluted float,
Dividendpershare float,
Cashfromoperatingactivities bigint,
Cashfrominvestingactivities bigint,
Cashfromfinancingactivities bigint,
Cashchangeduringperiod bigint,
Cashatendofperiod bigint,
Capitalexpenditures bigint,
Price float,
Pricehigh float,
Pricelow float,
ROE float,
ROA float,
Bookvalueofequitypershare float,
PBratio float,
PEratio float,
Cumulativedividendspershare float,
Dividendpayoutratio float,
Longtermdebttoequityratio float,
Equitytoassetsratio float,
Netmargin float,
Assetturnover float,
Freecashflowpershare float,
Currentratio float
);
create table dividends (Date date,
Dividends float,
Symbol VARCHAR(50));
 
create table prices ( Date date,Open float,High float,Low float ,Close float,AdjClose float ,Volume bigint ,symbol varchar(50));

Load the data into PostgreSQL using the steps below. You must be the admin user to copy these files to these tables.

COPY earnings FROM '/home/ubuntu/Documents/tableau/dis.dividends.csv' DELIMITER ',' CSV HEADER;
COPY earnings FROM '/home/ubuntu/Documents/tableau/sbux.dividends.csv' DELIMITER ',' CSV HEADER;
COPY earnings FROM '/home/ubuntu/Documents/tableau/jns.dividends.csv' DELIMITER ',' CSV HEADER;
COPY dividends FROM '/home/ubuntu/Documents/tableau/sbux.dividends.csv' DELIMITER ',' CSV HEADER;
 
COPY dividends FROM '/home/ubuntu/Documents/tableau/jnj.dividends.csv' DELIMITER ',' CSV HEADER; 
 
COPY dividends FROM '/home/ubuntu/Documents/tableau/dis.dividends.csv' DELIMITER ',' CSV HEADER;
COPY prices FROM '/home/ubuntu/Documents/tableau/sbux.prices.csv' DELIMITER ',' CSV HEADER;
COPY prices FROM '/home/ubuntu/Documents/tableau/jns.prices.csv' DELIMITER ',' CSV HEADER;
COPY prices FROM '/home/ubuntu/Documents/tableau/dis.prices.csv' DELIMITER ',' CSV HEADER;

How to join tables (right and left joins)

The common element among all these tables in the stock symbol. Tableau will automatically try to join the three tables—dividends, earnings, and prices—by the stock symbol. But we can’t allow this auto-join because the tables have different numbers of records. This is because Disney did not pay dividends in all 40 quarters, though Johnson & Johnson and Starbucks did. (Doing this, an inner join, in this case would drop some rows of data.)

So, you must do right or left joins, depending on what data you’re investigating. For our purpose, looking at earnings and dividends, we need to do a right join because there are more earnings than dividends.

To change the join type, double-click the double circles in Tableau Online.

This worksheet shows that Disney paid dividends only 15 out of 40 quarters. This is a bar chart of the stock symbol and cnt(Dividends), meaning dividend count.

As you work with worksheets, type over the name at the bottom and give them a descriptive name.

In the above worksheet, the plus (+) sign indicates that the two tables are joined. Notice that it shows the 3 tables as well as the joins you have defined in the data sources. Be careful to pick the correct table or relation when you make a chart.

Below, when you select dividends+ it lists fields from both tables on the left. These are the fields you can use in the worksheet:

How to reverse errors

If you mess up, you can simply reverse: click the left-hand arrow at the top to go back.

Earnings analysis

Let’s look at earnings. On the left, select the earnings table.

If you’ve read financial statements before, you know that they are shown in the thousands. So, create a calculated field earnings1000 to divide this large number by 1,000 to make it easier to see. We make this a calculated field.

Analysis: Disney earnings by quarter

We put the quarter filing date in the rows and the value we want to list in Marks section. This sums earnings per quarter, which is the same as listing the single value of earnings, since there is only one record per filing period.

Then, filter on the stock simple. We also filter on the Quarterend to pick only dates from 2010 to 2018, since that is the dates for which we have dividends and stock prices.

Now, using Disney, Starbucks, J&J, or your own company’s data, you can begin your analysis.

]]>
How To Make an Expense Report in Tableau Online https://www.bmc.com/blogs/tableau-how-to-make-expense-report/ Wed, 04 Mar 2020 00:00:00 +0000 https://www.bmc.com/blogs/?p=16584 This is the third installment in our series on Tableau. Here, I’ll explain how to use Tableau to do an expense report. We will illustrate basic Tableau concepts, such as writing formulas. Our previous articles on Tableau include: Tableau: Getting Started with Real Examples Using Tableau with PostgreSQL (This article is part of our Tableau […]]]>

This is the third installment in our series on Tableau. Here, I’ll explain how to use Tableau to do an expense report. We will illustrate basic Tableau concepts, such as writing formulas.

Our previous articles on Tableau include:

(This article is part of our Tableau Online Guide. Use the right-hand menu to navigate.)

Setting up Tableau with your data

We recommend using Tableau Online instead of the desktop version. (It costs $70 per user per month, with a free 14-day trial.) Salesforce acquired Tableau, so its future is in the cloud product. This means you can work from any place, without needing the desktop software.

For the data, use a credit card or bank statement or anything with categories, so that you can list expenses by category. We are using a credit card statement.

We loaded our data into PostgreSQL, as explained here. You can use PostgreSQL with a .cvs or .xls file, but you cannot do aggregations, so it’s not very useful. Therefore, load your data into PostgreSQL first. You could also use Apache Hive or any other the other data sources that Tableau supports.

Creating a bar chart

Here is a finished expense report for the months of January and February. If you want a graphical report, like this bar chart, then listing one month next to another is one option.

Another option is to make a stacked bar chart, or a spreadsheet-like chart, which is what we do below. (The screen will get too crowded to list a whole year in a bar chart format. We will explain how to solve that problem in future blog posts.)

Credit card payments are negative numbers. So, add a filter on the amount column to filter out your payments. (They are > 0.) Then, add a filter on the transaction postdate to limit it to two months. Otherwise you would have 12 charts drawn across the screen, which is too wide to read.

Further down we explain how to make filters and basic charts (You can refer to the previous articles for more details.)

We want to show negative numbers as positive for clarity. Use the ABS (absolute value) function. To do this, click on the amount field then select create calculated field.

Type in some suitable name at the top then write the formula below that:

To extract the month from the Postdate, write this calculated field:

This is what the screen will look like to make this report. The filters are at the top. Far to the right (shown above) is where you enter the filter ranges. Fields in the table located on the far left. To use them, simply drag them onto the worksheet, filter, or row and column areas or click add to worksheet.

Creating a worksheet

Now we switch to a worksheet-type display, as opposed to a chart. To switch to that display or other chart types, click the show me icon at the top right of the display.

A worksheet lets us plot more than two dimensions. (If you tried to make a chart out of this it would make an additional chart of every dimension greater than two, at least for the bar chart). Of course, you could try a 3-dimensional chart, but those are hard for users to understand.

Notice that we have Month and Category as Rows and no fields as columns. Then in the Marks section we have sum(charge). (Ignore Running Sum, as we are not using that.)

By default, Tableau will assume that we want a report of expenses by month (first) and category (second) since we listed month on the left and category on the right. It adds the function sum() to the amount since it assumes we want to aggregate that.

Calculating percent change

Now let’s calculate the percent change in expenses per month. (We drop the category as percent change by category by month is harder to do.)

The formula for percent change is:

(new value – old value) / old value

In terms of the data we have, that is the formula shown below. It’s not very sophisticated as the LOOKUP function is just a table function which means look up to the cell one row (-1) above the current row. In other words it’s applied to the displayed worksheet and not the underlying data.

(sum([charge]) – LOOKUP(SUM([charge]),-1))/sum([charge])

By default, Tableau will round off these numbers to integers, so most will be 0 or 1. So click on the value in the Marks panel and then click format to change it to a percent in order to see decimal points.

Here is the result:

]]>