Power BI How-To
How to make a treemap in Power BI
Build a treemap in Power BI: field wells, a worked example, when the native visual is enough, and how to generate the .pbiviz without code.
By Nawaf Sharaf · Founder & Reliability Engineer · Updated
A treemap shows composition as area: the biggest rectangle is the biggest category, and nested rectangles show what each one is made of. It is the fastest way to see where revenue, cost or exposure concentrates when the category list is long and hierarchical, which a pie chart with 60 slices cannot do.
Power BI ships a treemap, so the first question is whether you need a custom one at all. This guide gives the honest answer (only for two or more nesting levels, labels that behave in small cells, or colour from a second measure), then builds the hierarchy data, binds the wells and checks the first render.
Step-by-step
- 1
Shape the data for the treemap
Hierarchy columns (e.g. Line, Category, SKU) plus a numeric Value column. Optional SecondValue column drives color scale independently of size. In the finished visual those columns land in the Hierarchy, Size, Colour wells, so name them that way from the start.
- 2
Load a small sample into Power BI Desktop
Import the five category rows with Revenue and Margin % as numbers. Keep Laptops, the high-revenue and low-margin cell, so the colour scale has something to separate from size.
- 3
Describe the treemap and generate the .pbiviz
On VizForge, describe the chart in plain English and say what matters for this one: how many levels, and whether lower levels show at once or open on click; layout algorithm: squarified (default) or slice-and-dice if row order matters; colour: by top-level category, or from a second measure with a stated scale (red below 15%, green above 30%). The pipeline writes the TypeScript, type-checks it and packages a .pbiviz.
- 4
Import the .pbiviz into Power BI Desktop
In the Visualizations pane, open the three-dot menu, choose Import a visual from a file and select the .pbiviz. The visual appears in the gallery; add it to the page like any built-in chart.
- 5
Bind the field wells
Hierarchy: One or more text columns in order (Line → Category → SKU). Size: Numeric measure: the area of each rectangle. Colour: Optional numeric measure: fills each rectangle from a colour scale.
- 6
Check the first render, then format
A single flat level: the hierarchy columns were dropped as separate fields instead of into the one Hierarchy well in order. Rectangles that don't fill the canvas: BLANK sizes at a lower level. Filter them or give the measure a zero default. Then open the formatting pane and set padding between siblings and between levels.
Field wells the generated treemap exposes
After import, these are the data roles you drop fields into. The names come from the visual’s capabilities.json, which you can rename before packaging if your team uses different terms.
| Well | Takes | Note |
|---|---|---|
| Hierarchy | One or more text columns in order (Line → Category → SKU). | Drop the columns in top-down order; the visual nests in the order given. |
| Size | Numeric measure: the area of each rectangle. | Negative values can't be drawn as area; filter them out or use ABS with a colour flag. |
| Colour | Optional numeric measure: fills each rectangle from a colour scale. | Without it, colour follows the top-level category. |
Worked example
Revenue by product line and category, coloured by margin.
| Line | Category | Revenue | Margin % |
|---|---|---|---|
| Hardware | Laptops | 4.2M | 12% |
| Hardware | Monitors | 1.1M | 22% |
| Software | Licences | 2.6M | 71% |
| Software | Support | 0.9M | 48% |
| Services | Consulting | 1.8M | 31% |
What the chart draws: Three outer rectangles sized 5.3M, 3.5M and 1.8M, each split into its categories. Laptops is the largest cell and the reddest, which is the 'big but thin' story the chart is for.
Live preview
The AI alternative: Describe your treemap in plain English and VizForge generates the .pbiviz, source included. 5 free credits on signup, no card required.
Generate a treemap on VizForge →Without code: what to put in the prompt
The generator turns a description into the TypeScript, so the description is where the decisions live. For a treemap, say:
- How many levels, and whether lower levels show at once or open on click.
- Layout algorithm: squarified (default) or slice-and-dice if row order matters.
- Colour: by top-level category, or from a second measure with a stated scale (red below 15%, green above 30%).
- Label rules: which levels get labels, and the minimum cell share that still shows one.
- Whether a parent label sits as a header strip above its children.
Example VizForge prompt
Treemap with 3 levels: product line → category → SKU. Size by revenue, color by profit margin (red below 15%, green above 30%, yellow between). Show labels only when cell is at least 5% of total area.
Customise it: formatting options worth exposing
Anything you name as adjustable becomes a card in Power BI’s formatting pane, which a report theme can then set for every copy of the visual. For a treemap the options that earn their place are:
- Padding between siblings and between levels.
- Header strip height and font for parent labels.
- Colour scale endpoints when a colour measure is bound.
- Label visibility threshold (percent of total area).
- Border colour and width per level.
For changes the pane doesn’t cover, edit settings.ts and visual.ts in the source that ships with the download and repackage; or refine on VizForge and get a v2 that keeps everything you didn’t mention.
When native Power BI is enough (as of November 2026)
Power BI's built-in treemap is enough for one level of grouping with an optional detail level, colour by category or by a single-colour saturation, and standard tooltips. If that describes your chart, use it; it is certified, themeable and needs no admin approval. A custom treemap pays off when you need three or more nesting levels on one canvas, parent header strips, a diverging colour scale from a second measure, or label rules that keep small cells readable.
Limits of Marketplace treemap visuals
Marketplace treemaps that add deeper nesting usually fix the layout algorithm and the labelling rule, and colour-by-measure is one of the features most often kept for the paid tier. Because the wells are fixed, you can't bind a third measure (for example to size the border) and you can't change how negative values are treated.
The general trade-offs (per-user licensing, closed source, no new field wells) are the same for every chart type; see VizForge vs Microsoft Marketplace visuals for the full comparison.
Download, install and first render
The download is a standard .pbiviz plus the TypeScript source. Import it in Power BI Desktop (Visualizations pane → three dots → Import a visual from a file), add it to the page and bind the wells above. Then check the treemap against this list before you connect the full dataset:
- A single flat level: the hierarchy columns were dropped as separate fields instead of into the one Hierarchy well in order.
- Rectangles that don't fill the canvas: BLANK sizes at a lower level. Filter them or give the measure a zero default.
- Everything one colour: the Colour measure isn't bound, or its scale min and max match.
- Labels missing on obviously large cells: the threshold is set as a fraction (0.05) where the prompt said percent (5).
When to use a treemap
- Portfolio composition (asset class → sector → position)
- Revenue by product hierarchy (line → family → SKU)
- Cost structure breakdown (department → team → expense category)
- Market share within a crowded category
- Story viewership (channel → show → episode)
Frequently asked questions
Will the visual work in Power BI Service, Premium and embedded reports?
Yes. A .pbiviz is a standard Power BI custom visual and renders the same in Desktop, the Service, Premium and Premium per User capacities, and embedded scenarios. Tenant admins can restrict custom visuals to certified or organisational ones; if yours does, publish the .pbiviz as an organisational visual rather than importing it per report.
What if I need to change the visual later?
Two paths. Refine on VizForge with an instruction such as "add a target line" and get a v2 .pbiviz that keeps everything you didn't mention; or open the TypeScript source that ships with every download in VS Code, edit it and repackage with pbiviz package.
How many nesting levels does it support?
Up to 6 in practice. Beyond that, labels become unreadable. If you need deeper drill-down, generate a treemap that opens the deeper levels on click.
Squarified or slice-and-dice layout?
Squarified by default (more readable rectangles). Prompt for 'slice and dice' or 'strip layout' if you need a specific algorithm — VizForge supports them all.
Can color encode a different metric than size?
Yes. Prompt with something like 'size by revenue, color by margin percent' and the AI-generated visual decouples the two.
Will it drill through?
Yes — standard Power BI drill-through works via SelectionManager, and the visual supports 'expand next level' from the visual menu.
Put your treemap on a designed page
Free Design Studio page layouts. Download the background, theme and PBIP project, then import the visual into the slot.
Finance template
Travel & Expense ManagementHas a slot for it: “Spend by expense type”.
Public sector template
City Service Requests (311)Has a slot for it: “Requests by type”.
Marketing template
Marketing Campaign PerformanceHas a slot for it: “Spend by channel”.
Design the page around it, free
A custom visual looks best on a designed page. The free VizForge Design Studio lays out a branded report page at Power BI’s pixel size and exports the background image, a theme JSON and a PBIP project. No signup.
Open the free Design Studio →Guides for related charts
Reference
Data shape, DAX measures, related visuals.
Index
One guide per Power BI visual type, plus the Design Studio guides.
VizForge — AI-generated Power BI custom visuals.