#### dernières news, tutoriels, actualités, communautés

__This tutorial will show you how to simply create a venn diagram in Tableau, using “sample superstore” datasource. To create this chart, you will need 5 calculated fields.__

__ __

__ __

#### ABOUT VENN DIAGRAM

__ __

__Also known as “Set Diagram”, a Venn Diagram is a diagram present schematic representation of all the possible logical relationships between a collection of sets. Each set is typically represented with a circle. Objects categories are presented in their circle, and cross-category objects are placed in intersections area.__

__ __

__Note : This chart is used to easily present and communicate about all category combinations, it’s used in a schematic representation. It doesn’t provide good distributions or part of total and shouldn’t be used in this way.__

__ __

__ __

#### Prerequisite

--> Calculated Fields

__--> LOD__

__--> Dual axis__

__ __

__ __

__CREATE A VENN DIAGRAM__

__ __

__1- Connect To sample superstore and get category combinations__

__ __

__ __

__I chose to create my example of Venn Diagram in Tableau using ‘Sample Superstore’ datasource.__

__ __

__This datasource might not be greatest to create a Venn Diagram but it will let everyone can follow this tutorial and create his own Venn Diagram.__

__ __

__To connect Tableau to sample Superstore, you just have to choose this datasource under ‘Saved Data Sources’ on Tableau first panel.__

__ __

__ __

__ __

#### 2 - Create a 2 sets Venn Diagram

__ __

__In the example below, I will show you how to create a Venn Diagram presenting the number of customers who made some (at least 1) orders in 2017, those who made some orders in 2016 and the number of customers who made some orders in 2016 and in 2017.__

##### Identify your sets and sets combinations.

__ __

__The very first thing to do when you want to create a Venn Diagram in Tableau is to identify what are the 2 sets you want to display and create a calculated field which split your data into one of the two sets, or in between these sets.__

__ __

__To perform this, we will use LOD calculations :__

__In this case, we need to identify if a customer ordered in 2017, if a customer ordered in 2016 and if he/she ordered in both years 2016 and 2017. To do this, we will create the calculated field below:__

__ __

__ __

__> Purchased 2016 and/or 2017__

__{ FIXED [Customer Name]: max(if YEAR([Order Date])=2017 then 1 else 0 END)} +{ FIXED [Customer Name]: max(if YEAR([Order Date])=2016 then 10 else 0 END)}__

__ __

__ __

__What does this calculation make ?__

__It uses two LOD to perform the two tests on both years. These two LOD calculation are added in ordered to have the global results of these two statements for each customer.__

__ __

__ __

__ __

__ __

__In this case, a customer will be linked to one of these 3 values:__

__1 -> The customer ordered in 2017 but not in 2016__

__10 -> The customer did not order in 2017 but ordered in 2016__

__11 -> The customer ordered in both years 2016 and 2017. First LOD (= 1) + Second LOD (=10) = 11__

__ __

__Apply and move the calculation to dimensions (must be a discrete dimension)__

__ __

__This calculation, called in this example “Purchased 2016 and/or 2017” will be used in all the next calculations we will create. __

__Now that we have a calculated field to assign one set or a combination of sets to each customer, we will create a calculated field to rename all the different categories:__

__ __

__This calculation uses the one previously created and assign for each value an understandable name.__

__ __

__ __

__ __

__> Purchased 2016 and/or 2017 Label__

__CASE [Purchased 2016 and/or 2017]__

__ WHEN 1 THEN "Year N"__

__ WHEN 10 THEN "Year N-1"__

__ WHEN 11 THEN "Year N & N-1"__

__END__

__ __

__ __

__ __

__ __

__Note: You most probably noticed that I added some comments in my calculated fields. This is my method to remember the different values assigned for each sets (1; 10). You can also write this in the sheet caption so you will always be able to find easily what is the value assigned to each set.__

__ __

__ __

##### Create X and Y axis Fields

__ __

__Now that we can identify to which category our customers belong, we can start to create the Venn Diagram.__

__This Venn Diagram uses simple Trigonometry formulas to position each on the sheet, using the unit circle formulas. These formulas might seem complicated but the only thing you will have to do to make your calculations work is to replace the calculated field in the CASE with the one you created at the beginning of this tutorial.__

__ __

__ __

__ __

###### X axis

__> axis X 2 sets__

__CASE [Purchased 2016 and/or 2017]__

__ WHEN 1 THEN COS(PI())__

__ WHEN 10 THEN COS(2*PI())__

__ WHEN 11 THEN (COS(PI()) + COS(2*PI()) )/2__

__END__

__ __

__ __

__ __

__ __

__Note : The value assigned for the customers in between the two sets is simply the average of the two previous values.__

__ __

###### Y axis

__The Y axis formulas will be almost the same than the X axis calculated fields, except that we will use SIN() function instead of COS().__

__We will also split the formula into two calculated fields in order to use dual axis features. The first calculated field will display a circle for each set, and the second one will only show a text value for the set combination category.__

__ __

__ __

__ __

__Field creating the circles__

__> axis Y circles 2 sets__

__CASE [Purchased 2016 and/or 2017]__

__ WHEN 1 THEN SIN(PI())__

__ WHEN 10 THEN SIN(2*PI())__

__ //WHEN 11 THEN (SIN(PI()) + SIN(2*PI()) )/2__

__END__

__ __

__ __

__ __

__ __

__Field creating the text values for sets combinations__

__ __

__> Axis Y labels 2 sets__

__CASE [Purchased 2016 and/or 2017]__

__ //WHEN 1 THEN SIN(PI())__

__ //WHEN 10 THEN SIN(2*PI())__

__ WHEN 11 THEN (SIN(PI()) + SIN(2*PI()) )/2__

__END__

__ __

__ __

__ __

__Then, convert the 3 axis calculated fields to continuous dimensions.__

__ __

__ __

__ __

##### Create the chart

__ __

__ __

__ __

__Drag axis X to columns and the two Y axis fields to rows.__

__ __

__Right-click on the second Y axis fields on rows, and select Dual axis.__

__ __

__Synchronize the axis by right clicking on the second vertical axis (right side of the sheet) and selecting synchronize axis.__

__ __

__ __

__ __

__ __

__ __

__ __

__ __

__ __

__ __

__ __

__ __

__ __

__ __

__Use the first field we created as filter to exclude value 0 ( in this example field “Purchased 2016 and/or 2017” )__

Then, drag Purchased 2016 and/or 2017 Label on color shelf for both Y axis.

__ __

__ __

__ __

__ __

__ __

__ __

__ __

__ __

__ __

__ __

__ __

__ __

__ __

__On axis Y circles 2 set, drag Purchased 2016 and/or 2017 Label as label, and the measure you want to represent on label for both Y axis (in my example, COUNTD([Customer_Name])).__

__Adjust labels to be in center horizontally and vertically__

__ __

__ __

__ __

__ __

__ __

__ __

__ __

__ __

__ __

__ __

__ __

__ __

__ __

__ __

__ __

__ __

__ __

__ __

__ __

__Finally :__

__Set both marks shelfs to circles.__

__On field, axis Y circles 2 sets drag MAX([Number of Records]) on size and set the size to the maximum. Adjust color opacity for the circles.__

__ __

__Set axis range :In this exemple I used a [-3,5 ; 3,5] x-axis and a [-2,5 ; 2,5] x-axis__

__ __

__ __

__ __

__ __

__ __

__ __

__ __

__Set opacity to 0% axis Y labels 2 sets and integrate the sheet to your Dashboard !__

__ __

__ __

__ __

__ __

__ __

__ __

__ __

__ __

__ __

__ __

__ __

__ __

__ __

__ __

__ __

__ __

__ __

__ __

#### 3 - Create a 3 sets Venn Diagram

__The method is the same as the one used for the 2 sets Venn Diagram, we just have more points and combinations. In this part I will only give you the formulas you can use, please see the 2 sets venn Diagram chapter for more explanations.__

__ __

__ __

##### Define your sets and associated scores

__Exemple : Customers purchasing in the 3 product categories__

__ __

__// Your_category_Set1 = 1__

__// Your_category_Set2 = 10__

__// Your_category_Set3 = 100__

__ __

__{ FIXED [Your_Row_lvl]: MAX(if [Your_category]=" Your_category_Set1" then 1 else 0 END)}+__

__{ FIXED [Your_Row_lvl]: MAX(if [Your_category]=" Your_category_Set2" then 10 else 0 END)}+__

__{ FIXED [Your_Row_lvl]: MAX(if [Your_category]=" Your_category_Set3" then 100 else 0 END)}__

__ __

__ __

__ __

##### Create labels for you sets

__CASE [Your_Set_Definition&Scoring_Field]__

__ WHEN 1 THEN "Your_label_Set1"__

__ WHEN 10 THEN " Your_label_Set2"__

__ WHEN 100 THEN " Your_label_Set3"__

__ WHEN 11 THEN " Your_label_Set1&Set2"__

__ WHEN 101 THEN " Your_label_ Set1&Set3"__

__ WHEN 110 THEN " Your_label_Set2&Set1"__

__ WHEN 111 THEN " Your_label_All_Sets"__

__END__

__ __

##### Create axis fields

###### > x-axis

__CASE [Your_Set_Definition&Scoring_Field]__

__ WHEN 1 THEN COS(PI()/2+ 2*1*PI()/3)__

__ WHEN 10 THEN COS(PI()/2+ 2*2*PI()/3)__

__ WHEN 100 THEN COS(PI()/2+ 2*3*PI()/3)__

__ WHEN 11 THEN (COS(PI()/2+ 2*1*PI()/3) + COS(PI()/2+ 2*2*PI()/3) ) /2__

__ WHEN 101 THEN (COS(PI()/2+ 2*1*PI()/3) + COS(PI()/2+ 2*3*PI()/3) ) /2__

__ WHEN 110 THEN (COS(PI()/2+ 2*2*PI()/3) + COS(PI()/2+ 2*3*PI()/3) ) /2__

__ WHEN 111 THEN ( COS(PI()/2+ 2*1*PI()/3) + COS(PI()/2+ 2*2*PI()/3) + COS(PI()/2+ 2*3*PI()/3)) /3__

__END)__

###### > y-axis circles sets

CASE [Your_Set_Definition&Scoring_Field]

__ WHEN 1 THEN SIN(PI()/2+ 2*1*PI()/3)__

__ WHEN 10 THEN SIN(PI()/2+ 2*2*PI()/3)__

__ WHEN 100 THEN SIN(PI()/2+ 2*3*PI()/3)__

__END)__

###### > y-axis labels sets

CASE [Your_Set_Definition&Scoring_Field]

__ WHEN 11 THEN (SIN(PI()/2+ 2*1*PI()/3) + SIN(PI()/2+ 2*2*PI()/3) ) /2__

__ WHEN 101 THEN (SIN(PI()/2+ 2*1*PI()/3) + SIN(PI()/2+ 2*3*PI()/3) ) /2__

__ WHEN 110 THEN (SIN(PI()/2+ 2*2*PI()/3) + SIN(PI()/2+ 2*3*PI()/3) ) /2__

__ WHEN 111 THEN ( SIN(PI()/2+ 2*1*PI()/3) + SIN(PI()/2+ 2*2*PI()/3) + SIN(PI()/2+ 2*3*PI()/3)) /3__

__END)__

__ __

##### Build Your Venn Diagram !!!

__See Chapter 2 - "Create the chart"__

__ __

__ __

__ __