Showing posts with label Tips. Show all posts
Showing posts with label Tips. Show all posts

Dynamic Number Formatting

Dynamic Number Formatting

Dynamic Number Formatting in Tableau

Recently I saw some examples of Dynamic Number Formatting on Twitter, so I though I'd share a solution I came up with a few years ago. 

This solution uses some simple math to determine the base 10 of a number. Using that base 10 we can determine how to round it, and which numeric symbol it should have. Solution also removes 0 decimals, and handles negatives.

Copy/Paste this calc and change [Value] to the field you want to have dynamically formatted. NOTE* we are aggregating in the calc, so if you want to dynamically display a value that is MAX/MIN/AVG/ETC, change the aggregation in the formula.

//Determine if the value is negative
IF SUM([Value]) < 0 THEN '-' ELSE '' END
+
'$' //Dolar Symbol
+
//Get Int Amount by Dividing the Value by its' Base 1000 Value
STR(INT(ROUND(ABS(SUM([Value]))/POWER(1000,INT(LOG(  ROUND(ABS(SUM([Value]))/10,0)*10 ,1000))),1)))
+
//Determine if you need to show a decimal
//If the Modulo is zero, we just want to show blank (Ex 159.0K = 159K)
//Else we want to show the decimal value (Ex 159.4K)
IF (ROUND(ABS(SUM([Value]))/POWER(1000,INT(LOG(ABS(SUM([Value])),1000))),1)*10)%10 = 0 THEN ''
ELSE '.' + STR((ROUND(ABS(SUM([Value]))/POWER(1000,INT(LOG(ABS(SUM([Value])),1000))),1)*10)%10)
END
+
//Determine the Unit to display based on the Log Base 1000
CASE INT(LOG(ROUND(ABS(SUM([Value]))/10,0)*10,1000)) //Unit Symbol
WHEN 1 THEN 'K'
WHEN 2 THEN 'M'
WHEN 3 THEN 'B'
WHEN 4 THEN 'T'
ELSE ''
END

Creating a 4 Quadrant Square Chart




I recently saw a great chart from Pew Research via Steve Wexler on Twitter.


This shows a 2X2 Matrix of survey data in 4 quadrants of favor/oppose. This is a really great chart, and it can 100% be created in Tableau.

Ramon Martinez quickly showed how you can use Polygons to create it.


After looking at this for a minute, I realized that there are bar chart features in Tableau that would allow us to create this chart without data-prep.

Steps

When we look at the chart, there are things we can immediately take away, for one, there are 4 quadrants around a 0,0 center point. From this point, there are squares sized by area around it.

While we can't use the "Square" shape mark to do this, we can use Bar Charts to simulate a Square.

The key here is to use "Fixed" size for Bar Chart. We can do this by setting up a Continuous X Axis that will let us place the Bars according to a specific value (in this case Sales).

I am using a conditional calc to control where on the X Axis the SQRT of Sales will fall. For the right side of my quadrant, I want the SQRT of sales to be positive, for the left side I want them to be negative.

CASE MIN([Region])
WHEN 'Central' THEN -SQRT(SUM([Sales]))
WHEN 'East' THEN SQRT(SUM([Sales]))
WHEN 'West' THEN -SQRT(SUM([Sales]))
ELSE SQRT(SUM([Sales]))
END

Using the Circle Mark, you can see how this places the values.


Now that we have the X Axis, the next step is to get the Height. We are going to use a similar conditional calc to get this. For our Top 2 Quadrants, we want to get the Positive value for the SQRT of Sales, and the Bottom Quadrants we want to the Negative value for the SQRT of Sales.

CASE MIN([Region])
WHEN 'Central' THEN SQRT(SUM([Sales]))
WHEN 'East' THEN SQRT(SUM([Sales]))
ELSE -SQRT(SUM([Sales]))
END

Placing that on the Rows Shelf, we can start to see the shape of the chart.


The next step is to change the Chart Type to Bar, which will look a bit funny....


One of the great features to come out of Tableau in the version 10 series is the "Fixed" size option for Bar Charts. While the original intention for them was to create marimekko chart, but we can use the feature laterally to do other things (I do this alot). This let's use define a Width for the Bar Charts according to a measure. Since our X/Columns shelf is using a Continuous Dimension (which we got using LoDs), we take the opposite value of it an place it on the Size Mark and set it to Fixed.



Alternative Approach:

Quickly after writing this, I realized there was another option. Instead of using the Width Calc on the Columns Shelf, and then using - Width on the Size Mark, we can use MIN(0) on the Column Shelf and Width on the Size Mark. By turning Stack Marks Off, we can get the same result.



And that's it! Hope this helps.

Filter Actions as Parameter = New Tableau UX Options

IF YOU HAVE NOT READ http://drawingwithnumbers.artisart.org/using-a-filter-action-as-a-parameter/ BY JONATHAN DRUMMEY, STOP READING NOW! 

Everything I am going to show is based on Jonathan's technique to simulate a Parameter using a Dashboard Action. For my examples, I am using the Union Scaffold Technique. After you have read/understand his post, come back here to see some examples on how to use it?

After you have read Jonathan's blog post, let's start with some examples!

Connect Scatter Plot on Hover


As Jonathan describes in his post, the first thing I am going to do is Setup a Union scaffold of my datasource. This will allow me to set a Target and Source field to work off of.

Begin by setting up the sheet with Category and Year, then bringing over the blended Sales and Profit


Next, we need to setup a field that we will filter on, to identify which marks we need to do additional work with.

[Category Include]

[Category] + [IncludeExclude]

Note* Here [Include-Exclude] is driven by the Union, i.e. I have one Table be set to Include, and the other set to Exclude.

Add this to the detail shelf.

Next add the sheet to a Dashboard so we can setup a Dashboard Action. Then create a Dashboard Action like so.


Here we are doing a few things. One, we are setter the Filter to Select and Leaving it, we need this so the Action Filter Set remains in place on the Worksheet, so we can adjust it.

We are also setting up the Action so that it directly affects the sheet in question, i.e. I am using the sheet to filter the sheet.

Finally, I am using the Category-Include field as the filter. 

Go back to the Sheet and click on a mark.


As you would expect, the filter is working as we might expect. We clicked on a Category, and the sheet filtered it. So what's the trick?


Now on the Action Filter, notice that each Category has two values, one for Include and one for Exclude. By setting the Action to Exclude, we only remove one instance of the Category. This means we can use an LoD to identify which Category has been excluded.

So I am going to setup a Dual Axis that only renders when there is one category in the in view.

[Dual]

IF MAX({ EXCLUDE [Category-Include] : SUM(1) } = 1) THEN SUM([Sample - Superstore].[Profit]) END

*The trick: By excluding the [Category-Include] field, we can test to see how many "Categories" are in the view. If there is only 1, we know that we have excluded the other mark. So we can take that and tell Tableau to grab another instance of Profit. 

Add this to you sheet as a Dual Axis and Synchronize, remove Measure Names and change the Mark to Line.


Now we have what we need. So the last step is to go back to the Dashboard Action and set it to Hover and Show All Values


This will allow you to hover over marks, trigger the filter, then instantiate the Dual Axis.

And viola! Connect a Scatterplot on Hover!


Other Options

The following are gifs of other examples on how to utilize this trick. They all work on the same premise, just in slightly different ways.

Halo on Hover


Super Bump Chart Highlight


Dynamic Reference Bands with Highlight


Self Highlighting Bar Chart


Here are the examples in a workbook. Feel free to download it and play around with the concepts.

Note* This is a hack, and a bit buggy on Tableau Public.



Configurable Polygon Calendar


I've been working a lot with Polygons lately, trying to build more "templates" in Tableau that can be reused by the community. My last post on Polygon Hex Maps is a lot easier to implement than this one, if you follow it step by step. So instead of going through the hassle, here is a shortcut if you just want to use this, but don't care to go through building it yourself.

Shortcut:

This is going to be a really long post, because of all the calculations, so to make things easy, I'm going to give you a shortcut up front.

Go to this link


Download the workbook.

Then add your datasource to it, blend on Date, and drag whatever measure you are interested in onto the Color mark of the Polygon.

How it works:

If you are sticking around to see all of the Calculations for this, get ready, it's a lot.

Step 1: The Data

As always, we need to start with the Data. I had a few ideas in mind on how I wanted to set this up, but ultimately landed on a model I thought would be the most flexible.


The primary sheet to this data set has 4 columns: DayOfYear | Type | Type Major | Join.

There are 3 TypeMajors: Month | Weekday | Poly

That gets further broken down by the type within it, either the Month Name or Weekday name.

The DayOfYear is a bad naming convention, but I already wrote it and don't feel like changing it. This value is specific to the Typ, for the Polygon, it actually is the DayofYear (1-366), but for Month and Weekday, it is those corresponding values, January = 1, Wednesday = 3, etc.

This dataset then gets joined to a scaffold, used mostly for the Polygon Marks.


Data File for this can be found here:

https://drive.google.com/open?id=1tQUevWNIPzayIGJfalHbR1BuhAaDaeyl

Step 2: Parameters

Now that we have our Data, we want to setup some Parameters. These are what will allow us to have a configurable Calendar. 





Step 3: Base Date Calculations

After we have our Parameters, we need to start building a lot of calculations around it. 

[Date] =

DATE(DATEADD('day', [Day Of Year], MAKEDATE([Year],[Month Start],1)-1  ))

This is a dynamic calculation to let us build up a year of dates using the DayofYear field, and the Year/Month chosen in the Parameters. The idea of this is to make a date that can cross-years, which serves to benefit individuals working off a Fiscal Calendar.

[Month Switch] = 

CASE [TypeMajor]
WHEN 'Poly' THEN DATEPART('month', [Date])
WHEN 'Weekday' THEN [Point]
WHEN 'Month' THEN [Day Of Year]
END

Here we are using a simple case statement to change get the correct value based on the TypeMajor from our dataset.

[Month Order] =

IF [MonthSwtich] - [Month Start] < 0
THEN 13 + [MonthSwtich] - [Month Start]
ELSE 1 + [MonthSwtich] - [Month Start]

END

Building on top of the [Month Switch] calculation, we determine what the proper ordering of the months are based on the Fiscal Month start configured in the Parameter.

Now that we have our Month calcs, let's do the same for Weeks

[WeekSwitch] = 

CASE [TypeMajor]
WHEN 'Poly' THEN DATEPART('weekday', [Date])
WHEN 'Weekday' THEN [Day Of Year]
WHEN 'Month' THEN [Day Of Year]
END

Pretty much the same thing as [Month Switch]

[Param Weekday Order] = 

CASE [Week Start]
WHEN 'Sunday' THEN 1
WHEN 'Monday' THEN 2
WHEN 'Tuesday' THEN 3
WHEN 'Wednesday' THEN 4
WHEN 'Thursday' THEN 5
WHEN 'Friday' THEN 6
WHEN 'Saturday' THEN 7
END

Just setting up a calculation to determine the base days of the week driven off the parameter chosen by the user.

[Weekday Order] =

IF [WeekSwtich] - [Param-Weekday Number] < 0
THEN 8 + [WeekSwtich] - [Param-Weekday Number]
ELSE 1 + [WeekSwtich] - [Param-Weekday Number]

END

Similar to [Month Order], we need to figure out the correct order of the weekdays based on the selection from the user.

[Filter] = 

{MAX(DATEPART('dayofyear', [Date]) )} >= [Day Of Year]

Since our datafile has 366 days in it (to handle leap years), this just allows us to remove an "extra" date that might pop in.

Step 4: Positioning Calculations

Now that we have our date calculations in order, we need to build off of them to properly construct our calendar. We start by getting the overall base setup by months.

[PushX] =

([Month Order]-1) % 3

[PushY] =

INT(([Month Order]-1) / 3)

If this looks familiar, it's because this is the same functions as setting up a trellis, but here we are driving it by the [Month Order]

Setting up the Polygon Points

[PointAdjusterX] = 

IF [TypeMajor] = 'Poly'
THEN
    IF [Point] = 1 OR [Point] = 4 THEN 1
    ELSEIF [Point] = 2 OR [Point] = 3 THEN 2
    END
ELSE [Point]
END


[PointAdjusterY] = 

IF [TypeMajor] = 'Poly'
THEN
    IF [Point] = 1 OR [Point] = 2 THEN 2
    ELSEIF [Point] = 3 OR [Point] = 4 THEN 1
    END
ELSE [Point]
END

These calculations simply define the base points of the polygon. This is the same for all, but we will "move" by the data.

Bringing it all together

Now it is time to bring all of this together so that we can plot it in Tableau. We will start with the calculations used for the Polygons

[PolyX] = 

IF [TypeMajor] = 'Poly' 
THEN (([PushX]*7) + [WeekdayOrder]) + [PointAdjusterX]
ELSEIF [TypeMajor] = 'Weekday'
THEN ([PushX]*7) + [WeekdayOrder] + 1 + 0.5
ELSE ([PushX]*7) + 5.5
END + [PushX]

This is where things get fun. Essentially, this calculation is "moving" the polygons based on the Data and what has been configured in the Parameters. This will allow us to plot all of our dates on the X Axis, while having a nice space between them.

We also include logic for our other two TypeMajors Weekday | Month. This will allow us to use a Text Mark in a Dual Axis to work as Fake Headers.

[PolyY] =

IF [TypeMajor] = 'Poly' 
THEN (([PushY]*5) + DATEPART('week', [Date], [Week Start]) - { FIXED MONTH([Date]) : MIN( DATEPART('week', [Date],[Week Start])) }) + [PointAdjusterY]
END  + [PushY]*3.0

We are doing something similar for the Y, except we also figure out what the "WeekOfMonth" by subtracting the Week of our Date (by the weekstart) from the Min Week of that Month. All of this is driven by the parameters, so these dates are completely customized.

We only grab the marks for Poly so that we don't get weird polygons from our other data, we will bring that in on a Dual Axis.

Step 4: Plot the Polygon Calendar

1. Drag [PolyX] onto the Columns Shelf
2. Drag [PolyY] onto the Rows Shelf
3. Place [Date] on the Detail Shelf.
4. Change mark type to Polygon
5. Drag Point onto the Path Shelf
6. Drag [Filter] onto the Filter Shelf and Select True



Looking good! However, at this point, I have no idea what is what. So let's add some labels.

Step 5: The Headings

First, we need to create the calculation that will allow us to plot the Headings. We already have the points for the X defined on the PolyX calculation, so the next step is to get the Y coordinates.

[Y2] = 

IF [TypeMajor] = 'Weekday'
THEN ([PushY]*8) + 1
ELSEIF [TypeMajor] = 'Month'
THEN ([PushY]*8)
END - 0.5

This is giving us rows for the Month, and then the individual Weekdays. Since only the Order of the Weekdays will change on the X axis, here we just figure out where to place them on the Y.

[Label] = 

IF [TypeMajor] = 'Weekday'
THEN LEFT([Type],1)
ELSEIF [TypeMajor] = 'Month'
THEN [Type]
END

This will give us cleaner (smaller) names to work with so that we can fit everything in a nice space.

1. Drag [Y2] onto the Rows Shelf
2. Dual Axis and Synchronize
3. Change Mark Type to Text
4. Add Labels to the Text Mark
5. Remove Measure Names after you Dual Axis.
6. Hide Headers


At this point you could be done. And I'm sure alot of people would want to be. But I'm going to add just a bit more styling to this.

7. Drag TypeMajor onto the Size Mark
8. Drag TypeMarjor onto the Color Mark
9. Configure both so the Month is larger and darker than Weekday



Awesome! That's really nice. Now at this point, we can just use this as a calendar (if we wanted to), we can configure the Year to be whatever we wanted, set out Fiscal Month start and whatever day of the Week we run our business on.

But, where this comes in nicely is blending. We can take this and Blend on the Date, so show how various measures are performing on a full calendar view. We could use this for other things as well, such as Holidays.


Example shows blending, along with Proper Dates and values by Fiscal Starts.

Long post, lots of calcs. But I hope this comes in handy. And remember, you can always just download the Workbook, and bring your dataset in, if you don't feel like going through the steps.

Rody

Polygon Hex Map in Tableau



A while back, Matt Chambers wrote a really good post about how to Create Hex Maps in Tableau using Hex Shape marks. This was a derivative of the work Brittany Fong did on Tile Maps. I've always enjoyed both of these map alternatives, as it allows users to map geographic data, while preventing the Texas effect.


I have used Matt's technique/data file for a while to create Hex Maps. But one thing that I always struggled with was sizing of the Shape Mark. No matter how hard I tried, it was always difficult to get it "just right". So I decided to put together a new file that allows me to create a Polygon Hex Map.This has the benefit of reducing headache with Shapes, and how Tableau sizes them based on the the size mark, and the viz size on the Dashboard. It also ensures the placement of the Hex are always exactly in the correct place.

DATA FILE HERE!

https://drive.google.com/open?id=1tG3B4Muvbx0jFPZ6pQymp2xUDvrd3H0H

Step 1: Plot the Polygon

1. Drag the X and Y field onto the Columns and Rows Shelf
2. Drag State onto the Detail Shelf
3. Change Mark type to Polygon
4. Drag Point onto the Path Mark


Step 2: Add the Labels

The one downside of using Polygons is that we can't directly add labels to them. It's annoying, but there is a fairly simple workaround.

1. Drag Y2 onto the rows shelf
2. Dual Axis and Synchronize
3. Change Mark Type to Circle
4. Drag Abbreviation onto the Text Mark
5. Center align text
6. Change Circle Opacity to 0% (Hides Marks from view)


Step 3: Blend and Color

At this point, we just need to blend the Dataset we are using with this one (Blending on the State field).

1. Link Dataset on State
2. Drag whatever measure you want to visualization onto the Color Mark


And that's it! 


How to plot rank deviations



In this post, we are going to talk about how to plot two Ranks, and show the deviations between them. This post will be done using Superstore, and does not require any data modelling.

The goal of this viz is to allow users to compare two measure ranks among dimensions.

Step 1: Setting up the Ranks

The first thing we need to do is create a Parameter that allows the user to determine which measure they want to use as the Primary Rank (The 45 degree line). To do this, we want to first setup a simple Parameter.


Once we have our Parameter, we want to create a calculation to grab the rank of the measure selected.

[Primary Rank]

IF [Choose Primary Rank] = 'Sales'
THEN RANK(SUM([Sales]))
ELSE RANK(SUM([Profit]))
END

This calculation is simply switching between the Rank of Sales or Profit, based on the user selection.

Now that we have our Primary Rank, we need to find the Secondary Rank, or the rank of the measure we want to plot the deviation to.

[Secondary Rank]

IF [Choose Primary Rank] = 'Sales'
THEN RANK(SUM([Profit]))
ELSE RANK(SUM([Sales]))
END

This is the inverse of the Primary Rank, we simply grab the rank of whatever measure the user did not select.

Step 2: Plotting

Now that we have our calculation, the next step is to start plotting them.

We begin by placing our Primary Rank on the Columns Shelf, and Sub-Category (or whatever dimension you want to compare ranks on) onto the detail shelf. Set the Primary Rank to compute using that dimension.



Perfect, now we want to repeat this same process, placing the Primary Rank again on the Rows Shelf. This will create our 45 degree line of the Primary Rank, showing where those fall.

We also want to Reverse the Column Axis so that is starts at our lowest rank, and moves to the highest (1).


Well at this point, all we have is a line...

The next trick is to drag the Secondary Rank onto the Axis of the Row Shelf. The will generate the Measure Values/Names onto Tableau.


Once that is generated, Set the Secondary Rank to compute using the Dimension, in this case, Sub-Category. Also, reverse the Axis on the Rows shelf (same as column) so that 1 (our highest rank) is at the top.


Perfect, now that we have the bones of the Plot, we just need to do some cleanup.

Step 3: Cleanup

First thing we want to do is remove Measure Names from the Color Mark, and place it instead on the detail shelf. We are going to create another calculation to determine the color.


Now onto the color. We want a calculation that will auto-magically give us the difference between the Primary and Secondary Rank, so that we can better highlight the deviations.

[Color]

[PrimaryRank] - [Secondary Rank]

By taking the difference from the Primary and Secondary Rank, we will always get the Increasing/Decreasing value based on the user's Parameter Selection, as both of these calcs are determined by it.

Place that onto the Color Mark, compute using the Dimension (Sub-Category).


You can change color pallets if you wish, but using a Diverging palette, be sure to set the Center to 0, so that increase/decrease deviations have two different color.

The last thing we need to do is handle how to tell the user what is what. Since Axis Titles are not Data-Driven, we cannot change those at will. So instead we will rename our Axis to be Primary and Secondary Rank.

Then we will create a calculation we can place in the title that will inform our users on which is which.

[Title]

IF [Choose Primary Rank] = 'Sales'
THEN 'Primary Rank: Sales | Secondary Rank: Profit'
ELSE 'Primary Rank: Profit | Secondary Rank: Sales'
END  

There are many different ways you could do this, but I wrapped my into a calc for ease of use.

Place that on the Detail Mark, then simple add it to the Title.


And that's it. You can adjust this in whatever way you need for your data. You can even expand this by having multiple measures, and letting the user select both the Primary and Secondary Rank using two parameters.

Hope this helps!


Radial Mapping in Tableau

"As the Crow Flies" is an expression for the shortest path between two points (geographically) regardless of landscape. When working with geography, sometimes we want to see how various aspects of our business are performing relative to a central distance. In Tableau, we don't yet have a feature that let's us do this auto-magically, luckily though, it's not too hard to add!



Step 1: The Data

To begin, we need to identify some needs. To create the Radial Lasso in Tableau, we need data to plot the point. Here's the thing, the Lasso isn't really a part of the actual data, it's in support of it. We are merely using it for visual context to identify the circumference of our area. Additionally, we are going to make the central point be driven by a parameter, so we don't need to tie this to the points individually. With that being said, what do we do? Full Join


To begin, we need a dataset that already has the L attitude and Longitude in it. We don't yet have the ability in Tableau to reference the Generated Lats and Longs Tableau provides, so we need our own. We also need a dataset that has one column, Path, that has 360 rows. Rather than using this as a cross-join scaffold, I am going to instead Full Join it to my dataset. This will allow me to "add" it the data, without effecting the granularity of the dataset. This technique is very beneficial when doing layering, as we can bring two different datasets into one, without either one effecting the other.

Step 2: The Distance Calcs (For filtering)

Now that we have our dataset prepared, we need to start creating some calculations. First things first, let's create our Parameter. This is going to be used to to determine our central point, or the location we want to map the Radial Lasso around.


For this example, I am using a combined field of City and State.

Now that we have our Parameter, we need to use some LoDs to get the Latitude and Longitude of that selected City, State on every row.

These calculations are what we are going to use to find the distances (in miles) from our central point, to all others. This will allow us to "Filter out" any points that are going to be outside of our desired circumference. 

[SelectedLat1]

{MAX(IF [City and State] = [Parameters].[City and State] THEN [Latitude] END )}

[SelectedLon1]

{MAX(IF [City and State] = [Parameters].[City and State] THEN [Longitude] END )}

These calcs looks to see if the City and State match our Parameter, if it does, we grab those coordinates, and wrap them in a Fixed LoD that put's them on every record. This will allow us to access it very easily.

Now for a lot of Calcs. The formula I am using is Haversine, or great circle distances Additional information here https://rosettacode.org/wiki/Haversine_formula

To start we need to transform our Lats and Lons to be relative to a circle.

[lat1]

[selectedLat1]/180*PI()

[lon1]

[selectedLon1]/180*PI()

[lat2]

[Latitude]/180*PI()

[lon2]

[Longitude]/180*PI()

As you can see, we are taking our Parameter driven Lats and Lons, as well as, our Data's Lats and Longs, dividing it by 180 and multiplying it by PI.

Next we need to find there difference between those points.

[dlat]

[lat2] - [lat1]

[dlon]

[lon2] - [lon1]

Finally, we bring it all together and create the Distance Calculation. This will tell us (in miles) how far a point is from our central point (the point chosen in the parameter).

[Distance]

ROUND(3961 * 2 * ASIN(
    SQRT(
        POWER(SIN([dlat]/2),2) +
        POWER(SIN([dlon]/2),2) *
        COS([selectedLat1]/180*PI()) * COS([Latitude]/180*PI())
        )

),2)

Perfect! Now that we have our Distance calculation, we can create a parameter and filter to determine which points we want to keep in our visualization.

[Distance Filter]

[Distance]<= [Miles] OR NOT ISNULL([Path])

[Miles] is simply a Parameter that let's users input the distance they want. I am also including a provision to include my PATH (my circle data set we Full Joined in), which will allow us to still plot those points on our map. This will work as a great circle around the central point, i.e. I can select 100 miles, and get only the points that are within 100 miles (as the crow flies) from my selected point.


Perfect! Even though I have points all around the country, I am limiting those points to only be within 500 miles of the point I selected.

Here's the rub though, it's very hard to see where my central point it, or the total circumference of the area I am filtering on.

Step 3: The Radial Lasso Calcs

What I am about to show comes 100% from the amazing Emily Chen. She created a blog post on how to map a Circle on a map, and it is just fantastic! I am directly using here calcs here (with a slight mod). I recommend you checking out her post http://www.lesviz.com/blog/2016/09/13/how-to-draw-a-circle-in-tableau/

[Circle Latitude]

DEGREES(ASIN(SIN(RADIANS([selectedLat1]))
*COS(([Miles])/3961) + COS(RADIANS([selectedLat1]))
*SIN(([Miles])/3961)
*COS(RADIANS([Path]))))

[Circle Longitude]

DEGREES(RADIANS( [selectedLon1] ) 
+ ATAN2(COS(([Miles])/3961)
-SIN(RADIANS( [selectedLat1] ))
*SIN(RADIANS( [Circle Latitude] )),
SIN(RADIANS([Path]))*SIN(([Miles])/3961)
*COS(RADIANS( [selectedLat1] ))) )-90

If these calcs seem scary, don't worry, this can be copy/pasted in your solution.

So now that we have our Lasso Calcs, we need to bring it in together with our actual points. We want to have a single X/Y column so that we can leverage Tableau's mapping service (there are workarounds to get Dual Axis maps but let's keep it simple).

[X]

IF NOT ISNULL([Path]) THEN [Circle Longitude] ELSE [Longitude] END

[Y]

IF NOT ISNULL([Path]) THEN [Circle Latitude] ELSE [Latitude] END

For these calcs, I am just doing conditional plotting. This is where the Full Join comes in. For the dataset that has my Path field, I want to grab the Circle coordinates, and then my actual dataset I want to grab the raw coordinates.


Sweet, now that the hard part is done, we need to do some additional cleanup to make this look really good.

Step 4: A single point line is just a circle.

First trick coming at you fast! As you saw in the first image, I am using only a single X/Y, yet it appears as though I have two marks types, Line and Circle. So here is the trick, a single point line, is just a circle. So we can manipulate that feature to give the illusion of two chart types, even though it's really only one.

We being by changing our Mark Type to a Line.


Well that didn't work. Reason being, Tableau has no idea how to draw the correct oath right now. There are points everywhere. Luckily, we don't have to do much to resolve this, we simply take the [Path] field from our Circle Dataset and place it on the Path Mark. This will draw the outer line correctly for us. And, since our actual data didn't have a "Path" field, it will break those away, and make them individual marks.


Starting to come along! This is looking pretty good at this point, but we can improve it. For one, let's deal with the sizing. I want the Actual points to be sized by their Sales, and I want to make the line much thinner, so it doesn't draw too much attention. Luckily, we can do this by dragging sales onto the size mark.


Since our Circle Dataset didn't have any sales, we can use that (along with adjusting the size range) to make the line extremely thin, while giving our points a larger size. Remember, these points are circles, they are single mark lines, but we can treat them the same way as a circle.

Next, we want to separate these two elements even more visually. I want the Circle line to be a completely different color scheme from my points. So we need to create a calc to do that.

[Color]

IF NOT ISNULL([Path]) THEN -1
ELSE [Sales]
END

What I am doing here is setting up a color range I can manipulate. I know my sales are never going to be below zero, so I set my Circle to be that. Now I can create a color scheme that will "split" these two up.


Sweet. We can use a Custom Diverging color palette, with steps ,and a center point, to essentially create two different color palettes. Anything that is negative will be black, whereas anything positive will be on a range over blue colors (I really like this trick).

At this point, you could be finished, by I want to go for a slightly more modern look. Instead of having that line be solid, I want to make it dashed. So how do we do that? We (once again) manipulate features in Tableau.

As we saw by putting the [Path] field on the Path Mark, Tableau is breaking elements up into partitions. So to get our circle Dashed, we need to break up the circle into smaller partitions.

[BreakLine]

CEILING([Path]/2)

This calc will group our points into buckets of two. We can take this calculation, and put it on the detail shelf. Tableau will use this, along with the path, to only connect the points within each partition. This will give the illusion of a Dashed Line.


Woot! I would say, "And that's it", but this was a lot. That being said, there are a lot of visual and analytical benefits we can get from this chart. 

I hope you learned a few tricks, and saw Tableau in a different light. Tableau has a lot of amazing features, but it's when we use those features in unconventional ways, that the real fun begins.