Tableau: Graph X on month with different year as colored lines - tableau-api

I'm trying to recreate the following Excel-created graph in Tableau. My data has traffic organized by month-year Eg., 01-01-2016, 02-01-2016 ...etc. for each year. Would changing the data format be required, or can I work with this as is?
I'm following the tutorial here but the closest I can get is:

There are two ways to accomplish this easily.
1. Change the marks card type from Automatic to Line.
Use Show Me (upper right) and select the icon for the line chart.
Additionally, here is some information on Discrete vs Continuous Pills which cause many new users confusion.
Discrete = Distinct buckets like apples, oranges, peaches, etc
Continuous = Any values on an axis like percentage, sales, etc
For dates, discrete dates are parts of the month like days (1, 2, 3...), months (Jan, Feb, March...). A continuous date would be Jan 2019, Feb 2019, etc (these are truncated dates because they include the entire date starting from earlier in time to later in time.
In the picture, the list in green is continuous and the list in blue is discrete.

Related

Rolling 7 Day Periods in Tableau

I’m trying to figure out how to create rolling 7 day periods. I have horizontal bar charts that are currently grouped by week, but I actually want them to be grouped by 7 day periods instead.
I used the Superstore data as an example. The top row in this image should be the last 7 days, with the latest date being in the top right, and so forth. Is this possible?
You can create a field to use as a dimension for this assuming you choose some anchor date to specify the beginning of a 7-day period. For this example, I’ll choose a literal date of July 4, 1776 but you could use the Today() function or the min or max transaction date in your data or whatever you like.
Then the DIV() and DATEDIFF() functions are all you need to calculate the number of 7 day periods Between the anchor date and the period containing [Order Date].
DIV(DATEDIFF('day', #7/4/1776#, [Order Date]), 7)
You’ll typically want to treat this field as a discrete dimension.
In the example below, I called the field [Period] and also displayed the earliest and latest dates found in the data for each Period.
In a more production oriented example, you may want to hide the header for the Period field and instead calculate the start/end dates for periods rather than draw them from the data, so that they show correctly if there were period boundaries without any transactions.
The formula to compute the [Period Start] is DATE(DATEADD('day', [Period] * 7, #7/4/1776#)) and to compute [Period End] is DATE(DATEADD('day', [Period] * 7 + 6, #7/4/1776#)) If you are going to use the anchor date in many formulas, it would be convenient to define it in one place with a parameter or calculated field.

How to draw continues lines across panels in Tableau

I want to plot a couple of measures by months over the last three years. The plot would be divided by year. So I put year and month for columns and the measure values for rows. The year is defined as DATEPART('year', [Month Date]) and month is DATEPART('month', [Month Date]).
The plot looks like this.
The lines are broken between years. Both YEAR and MONTH are blue (discrete), but if I change them to green (continuous), the lines are connected but it looks weird.
I wonder how to make continuous lines across year?
What has happened is you have converted a date part (i.e. Month = March) to a continuous unit. What this does is simply changes March to 3. This looses the context of what the actual date is (i.e. March 2007). To change this right click on the date field on the column. You will see two separate areas to format the dates i.e. there are two years (2015, 2015), two quarters (Q2 and Q2 2015) etc. The first is a date part and the second is truncated date from the original date/timestamp.
You want to change the format to the second Month option (Month May 2015) and ensure the data type is continuous.
This should give you a continuous line across the year. If not screenshot me where you get to and I can assist from there.
Check if the last week and first of the next year is the same, I have a similar issue and solved it by passing the dates as Day-Month-Year.

Tableau: graphically show compounded leadtimes

I have a chart that shows the number of departures for a given 15 minute interval as seen here.
I need to compound these counts backwards for one hour. For example, the 3 departures shown at 11:00 need to also be represented at the 10:00, 10:15, 10:30, and 10:45 columns. When completed, the 10:00 would have a total of 6 departures (10:15 -> 6, 10:30 ->5, 10:45 -> 4, 11:00 -> 4).
I have done this via VBA in excell, but am now needing to replicate the chart in Tableau and have been beating my head in for about two weeks now. I'd love to hear any and all suggestions.
You can use a Cartesian join against a large enough date range of your choosing to in effect resample your data and add the additional time intervals you desire.
For example, if you have a month's worth of data (min date -> max date = 30 days), then you have (30 * 24 * 4) 2880 15 minute intervals.
Create all those intervals in a separate data sheet
Add a bogus column with value of link for all rows
Create the same bogus in your actual data source
Join the two sheets together on the link column
Create a calculated field that is something along the following:
[Interval] <= [Flight Time] AND [Interval] >= DATEADD('hour',-1,[Flight Time])
This calculated field will evaluate to TRUE when the interval time is within one hour before the flight time. You can then drag this field onto your filter shelf and select TRUE value only. Effectively your [Interval] field becomes your new date field.
I would recommend adding that filter to the context and applying across the entire datasource. Before you add this filter you'll have 2880 times the about of data so be sure to do a live view first. Be careful with extracts using Cartesian joins as you could potentially be extracting more than you bargained for.
See the following links for different techniques on how to do this and re-sampling dates in general in tableau.
https://community.tableau.com/thread/151387
Depending on the size of your data (and if a live view is not necessary) it is often times easier and more efficient to do this type of pre-processing outside of tableau in SQL or something like python's pandas library.
Here is another solution provided from the Tableau Cumunity Forum. I have not tried tyvich's solution yet, but I know this one got me where I needed. Please follow the link to see the solution using moving table calculations.
https://community.tableau.com/thread/251154

Tableau: Calculate Monthly and Yearly Averages from Days

I have a few years of data by day that looks like this:
Date Count
1/1/2015 1000
1/2/2015 1010
1/3/2015 1040
I would like to create a calculation that allows me to switch between Day, Month and Year using Tableau's date formats without having to calculate the average for each individual format. For instance, the monthly average for Jan 2015 would be the total of Count for all 31 days in January 2015 divided by 31.
Since you have no missing data (days) and no duplicate data, the solution is extremely easy.
Place the Count field on any shelf (except the filter shelf). For example, place it on the Rows shelf. Click on the Count field on the Rows shelf and change the aggregation to AVG(). You should see the AVG(Count) of all your data rows at this point.
Place the Date field on any shelf (except the filter shelf). For example, place it on the Columns shelf. Click on the Date field pill on the Columns shelf, and choose the level of granularity you wish from the SECOND batch of choices. (The first batch returns date parts, not dates) For example, choose Month. You'll see the Avg(Count) per month.
Place any other dimensions on shelves to either filter to specific dimension values or to show the average counts broken down by your other dimensions.
Users can drill up or down the granularity of your dates by clicking the + or - icons by the date axis, or by clicking on the Date pill. You can choose to display the dates as a continuous or discrete value.
If you don't like the +/- UI, then you can create a string valued parameter with values: year, quarter, month, day etc, and then create a calculated field using the date_trunc() function to allow, say, a dashboard user to to choose the date granularity from a different type of UI control.

Aggregating data from the US stock market in Tableau, using different time frames

I am a very basic user of tableau and I have not found an answer to my question.
I have a txt file that has historical daily data for 98% of all the stocks in the US, with their daily capitalization. Each stocks has its TICKER, Daily Market Value for every trading day of the year, and its SECTOR.
I did a simple time series that display SUM([Mktval]) (sum of all individual market values) across all stocks, on a daily daily, and where I can see that the total value as of 2016 is about 24 Trillion USD, as in the image below.
When I change the view column from DAY to YEAR, I don't see the right values, but something a lot larger. So I realized that I need to do SUM([Mktval])/252 to get the right value for a year (there are 252 trading days in a year).
If I change the view to MONTH, as in the chart below, the numbers are again wrong because 252 is not the right value to use in the division.
Is there any way that Tableau can adjust the values automatically to reflect the AVG MktVal across different time intervals?
Thanks
Replace SUM(Mktval) on the Rows shelf with the following calculated field
avg({ fixed day(Date1) : sum(Mktval) })
That solution is all in one step. It is perhaps a bit more clear to use 2 steps. First, create a calculated field called total_daily_market_value defined as
{ fixed day(Date1) : sum(Mktval) }
Then make sure that calculated field is a measure. It is an LOD calculation that you can think of as a separate table with one value for each day showing the total market value for that day.
Drag that measure to a shelf, and then change the aggregation function to AVG(), MEDIAN(), MIN(), MAX() or STDEV() as desired. Tableau will aggregate the total_daily_market_value using your chosen aggregation function for whatever values of Date1 are in your view.