Microsoft Power BI Complete Reference
上QQ阅读APP看书,第一时间看更新

The Treemap visual

A fantastic visual for displaying hierarchies is definitely the Treemap visual. It accomplishes this by nesting the data in rectangles, which are represented by color, and this is commonly known as a "branch". If you add a category into the Details section of the visual you will note smaller rectangles within the "branches" and these are known as "leaves", hence the name Treemap. In order to really maximize this visual, we will need to do a little extra setup and bring in a new table, and create a new hierarchy. Let's go through this process now:

Let's look at, setting up the example:

  1. We need to bring in the DimGeography table from the AdventureWorksDW excel workbook. Since we accomplished this during Chapter 3Building the Data Model, you should be able to see this source under the Recent Sources option. If not, you can connect to this source by pointing to this location: C:\Packt\Data Sources\AdventureWorksDW.xlsx.
  2. Once the Navigator appears, we will want to place a check mark next to the DimGeography table and hit Load.
  3. We need to do a couple quick fixes to this new table before we can leverage it. Navigate to the Relationship View and delete the inactive relationship between Sales Territory and DimGeography.
  1. Also let's rename this new table to Geography and hide the following fields: FrenchCountryRegionName and SpanishCountryRegionName.
  2.  Lastly, let's create a new hierarchy that we will use inside of this Treemap visual, as well as the Map visuals later on. Right-click on the EnglishCountryRegionName column and select New Hierarchy from the dropdown. Rename the new hierarchy Region Drilldown.
  3. Add StateProvinceName to the hierarchy by right-clicking on it and selecting Add to Hierarchy from the dropdown. Repeat this step for the City field. See Figure 5-12 for reference:
Figure 5-12

Now that we have a new geographical hierarchy that goes all the way down to a city level, we can see how this will display with our Treemap visual.

Let's look at, setting up the visual:

  1. Click on any of the white space on the report canvas to ensure no visual is selected, and bring in the Treemap visual.
  2. Move and resize this visual so that it takes up a quarter of the remaining report canvas.
  1. First. we must decide on what we will be grouping on, and in our situation. that will be the newly defined Region Drilldown.
  2. Next. we will add the Total Sales measure to the Values area and we start to see the beauty of this visual.
  3. The last thing we will add is to the Details area so that we can see some "leaves". Bring in the Year field from the Date (Order) table.

The size of each of the rectangles is determined by the value being measured, which in our case is Total SalesThe "leaves" in this visual are portrayed by the Year category while our Region Drilldown creates the "branches". Because we are using a hierarchy, we have full access to the Drilldown capabilities shown earlier. You should also now be able to tell that the Treemap visual arranges the rectangles by size from top left (largest) to bottom right (smallest).