Tableau Maps are handy to visualize the geographical data. In this section, we show how to Create a Map in Tableau with an example. For this Map demo, we are going to write the Custom SQL Query against the SQL Server Data Source.
-- SQL Query to create a Map 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
A first approach to Create a Map in Tableau
Double-click on any Geographic filed such as City, Postcode, Country, or State will automatically create a Map in Tableau. In this map example, we will double-click on the State Province Name dimension. The Tableau had added the Latitude value to Row shelf, Longitude value to Column shelf, and State province Name to Details field present in Marks Shelf.
The second approach to Create a Map in Tableau
Drag and drop any Geographic filed such as City, Country, Postcode, or State on the Details field will automatically create a Map in Tableau. Here, we will drag the State Province Name dimension to Details field present in Marks Shelf
Now you can see the auto-generated map.
You can also add the geographical hierarchy, as well. We have added the State province hierarchy (province Name, City) to the details shelf.
The third approach to Create a Map
Please drag and drop any Geographic filed to Column, or Row shelf and selecting the Map from Show Me window will automatically create a Map in Tableau. Let’s drag the State Province Name dimension to Columns Shelf and selecting the Map present in Show Me Shelf
That will automatically create a Map
Let us add Sales Amount Measure to Colors field in the Marks Shelf. It will add color to each state in a map based on the Sales Amount that occurred.