Treemaps in Power BI: many parts of a whole at once

What a treemap in Power BI shows, branch and leaf nodes, the Category, Details and Values fields, when it beats a bar or pie chart, DAX for share and colour, and the limits of comparing rectangles.

Short answer: a treemap fills a rectangle with smaller rectangles, each sized by its value, so it shows many parts of a whole at once, and parts within parts. In Power BI, the Category field makes the coloured branch nodes, the optional Details field splits each branch into leaf nodes, and Values sizes them. The largest branch sits at the top left, the smallest at the bottom right. Use it when there are too many categories for a pie and the question is "what are the big blocks?".

The chart, part by part: What is a treemap? draws its parts and shows how to read one, its kinds and the mistakes to avoid.

A pie with 30 slices is useless, and a bar chart with 30 bars shows the ranking but not that the top five make up 70% of the total. A treemap shows both: the big blocks dominate, the long tail shrinks to small tiles.

What does a treemap look like?

Bikes620Accessories180Clothing120Components80Services50
Revenue by product category (in thousands), largest top left

When is it the right chart?

Microsoft lists the cases: large amounts of hierarchical data; more values than a bar chart can show well; proportions between each part and the whole; how the measure is spread across each level of a hierarchy; size and colour as two attributes at once; and spotting the biggest contributors, outliers and exceptions.

The dataChart
2 to 5 partspie or donut
Up to about 15 parts, exact ranking mattersbar chart
Many parts, or parts within parts, the big picture matterstreemap
Parts compared precisely with each otherbar chart (areas are hard to compare)
Treemap, pie or bar

How do you build one?

  1. In Visualizations pick Treemap. The wells are Category, Details, Values and Tooltips.
  2. Drag the measure to Values and the top level, for example Product[Category], to Category.
  3. For leaves, drag a second field to Details, for example Store[Chain]: each category is split into chains, coloured as their category.
  4. Turn on Data labels and Category labels in Format visual; small tiles hide their labels when they do not fit, so the hover tooltip carries the rest.

A treemap highlights and cross-filters like other visuals: selecting a tile filters or highlights the other visuals on the page, and selecting elsewhere highlights the matching part of each tile.

What DAX goes with a treemap?

The share of each tile, for the tooltip:

Share of Revenue =
DIVIDE ( [Revenue], CALCULATE ( [Revenue], REMOVEFILTERS ( 'Product' ) ) )

Size and colour can say two different things. Size by revenue, colour by margin: Format visual, Colors, fx, Gradient based on Margin %, so a big pale tile is a big seller with a thin margin.

Margin % =
DIVIDE ( [Revenue] - [Cost], [Revenue] )

With colour by a measure, the tiles no longer share their category colour; that is the point, but say so in the title ("size: revenue, colour: margin").

What goes wrong?

  • Comparing similar tiles. Two tiles of 12% and 14% look the same, and a tall thin tile looks smaller than a square one of the same area. Put the numbers in labels or tooltips, or use bars for the comparison.
  • Negative values. A tile cannot be negative; categories with net returns vanish.
  • Too many levels. Category and details are plenty; a third level turns tiles into confetti. Drill instead.
  • Colour that means nothing. Default colours per category are decoration; if colour carries a measure, add a legend that says so.

Where can you check this?

Where do you start?

Use a treemap for "what are the big blocks?" across many categories, add a Details level only if it helps, and keep exact comparisons for a bar chart. The pie chart post covers the small-whole case, and the decomposition tree breaks a total down level by level.

Keep reading

More from the blog.

Every post

Next

Building this? Say hello.

A question about this post, a pattern you would build differently, or the next thing you want written out: Behnia reads every message.