In Tableau, we can create Pivot data (also called as Text Labels, or Crosstabs) by placing one dimension in Column shelf, and another dimension in Row shelf. Let us see how to Create a Tableau Text Label with an example.
For this Tableau Text Label demo, we are going to write the Custom Query against the SQL Server Data Source.
-- SQL Query to create a Text lable in Tableau SELECT ProdCat.EnglishProductCategoryName, ProdSubCat.EnglishProductSubcategoryName, Geo.EnglishCountryRegionName, Geo.StateProvinceName, Geo.City, Geo.PostalCode, Geo.IpAddressLocator, Prod.EnglishProductName, Prod.Color, Prod.DealerPrice, Cust.FirstName, Cust.LastName, Cust.Gender, Cust.YearlyIncome, Cust.EnglishEducation, Cust.EnglishOccupation, Fact.OrderQuantity, Fact.TotalProductCost, Fact.SalesAmount, Fact.TaxAmt, Fact.OrderDate FROM DimProductSubcategory AS ProdSubCat INNER JOIN DimProduct AS Prod ON ProdSubCat.ProductSubcategoryKey = Prod.ProductSubcategoryKey INNER JOIN DimProductCategory AS ProdCat ON ProdSubCat.ProductCategoryKey = ProdCat.ProductCategoryKey INNER JOIN FactInternetSales AS Fact ON Prod.ProductKey = Fact.ProductKey INNER JOIN DimCustomer AS Cust ON Fact.CustomerKey = Cust.CustomerKey INNER JOIN DimGeography AS Geo ON Cust.GeographyKey = Geo.GeographyKey
Create a Tableau Text Label
In this example, we are going to create a text label in Tableau. For this, first drag and drop the English Product Subcategory Name from Dimensions Region to Rows Shelf, and Order Date (Year) to Column Shelf.
Next, drag and drop the Sales Amount from Measures Region to Text field present in Marks Shelf.
From the above screenshot, you can see we don’t have much data for the years 2010 and 2011. So, we excluded those years by selecting those columns in a report and chose the Exclude option from the tooltip.
Next, drag and drop the English Country Region Name from Dimensions section to Rows Shelf on the left side of the product subcategory.
The above screenshot shows the complete Tableau Text Label cross tab report. Let us interchange the positions of the dimensions in Row shelf.
Here, we replaced the product subcategory name in row shelf with the color dimension
Add Table Calculation to Tableau Text Label
To add the Tableau table calculation as a text label, please select and right-click on the Sales Amount measure (change as per your requirement) will open the context menu. Here you have to choose the Add Table Calculation option, as shown below.
Once you select the Add Table Calculation option, a new window called Table Calculation will open. Here we are choosing the Calculation Type as the percent of Total and Computed by Table (crosstab). Remember, we will discuss the Table calculations in another article, and here we will focus on the crosstabs report only.
The following screenshot will show you the Tableau text label or Crosstab report along with the Percentage total. As you can see, we got the maximum percentage of sales in 2013 compared to 2012 and 2014.