Sub topic 11
Looking at distributions with binned charts
This chapter assumes you can build a basic column chart in Power BI Desktop. It also assumes you have a loaded model with a Product table and a Sales table, and that you know the difference between a column and a measure. You don't need advanced DAX.
What a distribution question asks
A distribution question asks how values are spread, not what they add up to. Examples:
- How many products sit in each price range?
- Are most orders small, with a few very large ones?
- How are customer ages spread?
Power BI has no built-in histogram visual. The usual approach is to turn a numeric field into ranges called bins, then count rows per bin in a column chart. A bin is a fixed range of values, such as 0 to 49 or 50 to 99.
This works because the chart's axis is now categorical (the bins), and the value is a count. Each column's height shows how many items fall in that range.
Method 1: a bin group in the field list
The quickest route needs no DAX.
- In the Data pane, right-click
Product[ListPrice]and choose New group. - Set Group type to Bin.
- Choose either Size of bins (for example 50) or Number of bins (for example 10).
- Select OK. Power BI adds a field named
ListPrice (bins)to the table. - Create a clustered column chart. Put
ListPrice (bins)on the X-axis andCount of ProductKeyon the Y-axis.
The bin field is a column in the model. It behaves like any other categorical field, so slicers and cross-filtering work with it.
Gotchas:
- Bin groups are built from a column, not from a measure. You can't bin a measure such as
[Total Sales]. To see how total sales per customer are spread, first make a column or table at the customer level, then bin it. - Bin size is fixed when you create the group. If the data changes a lot, edit the group again.
- Labels show the lower edge of each bin. A bin labeled
50holds values from 50 up to, but not including, 100 when the size is 50. - Blank values in the source column land in a blank bin. Decide whether to keep or filter them.
Method 2: a calculated column
A calculated column gives you control over labels and boundaries. The spine example groups prices into named bands:
Price Band =
SWITCH (
TRUE (),
Product[ListPrice] < 50, "Under 50",
Product[ListPrice] < 200, "50 to 199",
"200 and over"
)Power BI sorts text alphabetically by default. The chart will show "200 and over", "50 to 199", "Under 50", which is the wrong order. Fix it with a numeric sort column:
Price Band Order =
SWITCH (
TRUE (),
Product[ListPrice] < 50, 1,
Product[ListPrice] < 200, 2,
3
)Select Price Band, open Column tools, choose Sort by column, and pick Price Band Order.
If you want equal-width bins with numeric labels, FLOOR is shorter:
Price Bin 50 =
FLOOR ( Product[ListPrice], 50 )This rounds each price down to the nearest multiple of 50. The result stays numeric, so it sorts correctly. A price of 137 becomes 100, and a price of 49.99 becomes 0.
Supplying the count
For the Y-axis you can drag a column into the Values well and set the aggregation to Count. A named measure is clearer and reusable:
Product Count = COUNTROWS ( Product )Use COUNTROWS when each row is one item. If the question is how many distinct customers fall in each bin, count distinct customer keys on the table that holds one row per customer. Counting transactions would count customers once for every order.
Choosing between the two methods
| Need | Better choice |
|---|---|
| Quick look at the shape of the data | Bin group (Method 1) |
| Equal-width numeric bins with correct sorting | `FLOOR` calculated column |
| Business-named bands such as "Under 50" | `SWITCH` calculated column plus a sort column |
| Bin edges that must follow a policy or table | `SWITCH`, or a separate band table |
| Binning a measure | Neither. Build a table at the right grain first |
Making the chart read as a histogram
A histogram's columns touch, because the bins are continuous ranges. A default Power BI column chart leaves gaps. In the Format pane, reduce the Spacing between categories (the inner padding setting) to a small value. Then the shape of the distribution is easier to see.
Other settings that help:
- Turn on Data labels if exact counts matter. Leave them off if the shape is the point.
- Keep the Y-axis starting at zero. Column length encodes the count.
- Title the axes plainly, for example "List price band" and "Number of products".
- Leave all columns one color, unless you highlight one band on purpose.
Choosing bin width
Bin width changes what the chart shows.
- Too few bins hide structure. A skewed or two-peaked distribution looks like one block.
- Too many bins leave small counts in each, so the chart looks noisy.
- A good start is 5 to 12 bins. Try two or three widths before deciding.
Avoid unequal widths in numeric bins. The Price Band example above has widths of 50, 150, and open-ended. The top band will collect many more items simply because it covers a wider range, which can look like a spike. Use unequal bands only when the bands have business meaning, and say so in the title or a subtitle.
A column chart of counts also can't show the exact median, spread, or outliers. If you need those, a table of summary measures (MEDIAN, MIN, MAX) next to the chart is a good built-in complement. A custom box-and-whisker visual from AppSource is an option when those statistics are central, but see the chapter on custom visuals before adding one.
Common errors
- Bins in the wrong order. Text labels sort alphabetically. Add a sort-by column.
- Counting the wrong thing. Counting sales rows when you meant products or customers.
- Percent instead of count. If you need shares, use a measure such as
Sales % of Totalstyle logic withDIVIDE, or set the visual to show a percentage of grand total. State clearly which one the axis shows. - Bin field not appearing as a category. If a numeric column is still summarized on the axis, set it to Don't summarize. Bin fields made by grouping normally avoid this.
- Slicers changing bins unexpectedly. Bins are fixed per row, so filtering changes the counts, not the bin edges. This is usually what you want.
Exercise
A Product table has a ListPrice column. You build a column chart with a SWITCH-based Price Band column on the X-axis, and the bands appear as "200 and over", "50 to 199", "Under 50". What two steps fix the order, and which measure supplies the Y-axis values if each row in Product is one product?
Show answer
Create a numeric column (for example Price Band Order, returning 1, 2, 3 using the same SWITCH conditions), then select Price Band and use Sort by column to sort by Price Band Order. For the Y-axis, use a count measure such as Product Count = COUNTROWS ( Product ).
Exercise
A colleague asks you to show how many customers fall into each range of total lifetime sales, but lifetime sales exists only as the measure [Total Sales]. Why can't you create a bin group on it, and what should you do instead?
Show answer
Bin groups and calculated column bins work on columns, not measures. Build a customer-level column or table that holds lifetime sales per customer (for example a calculated column on Customer that uses CALCULATE ( [Total Sales] ), or a summary table), then bin that column and count customers per bin.