Sub topic 11
Looking at distributions with binned charts
A distribution shows how values spread across a range. It answers questions such as "Are most of our products cheap or expensive?" or "Are order sizes clustered or scattered?" This chapter assumes you can build a column chart, add fields to the field wells, and write a simple DAX column. It covers two ways to build a histogram-style view in Power BI.
Why a distribution needs binning
A column chart needs a category on the axis. A numeric field such as ListPrice has many distinct values, so plotting it directly gives one thin column per price. The result tells you nothing about the shape of the data.
Binning groups the numbers into ranges, called bins. You then count how many rows fall into each bin. The tall and short columns show where values concentrate.
Option 1: Built-in bins
Power BI can create bins for you.
- In the Data pane, right-click the numeric field (for example
Product[ListPrice]). - Choose New group.
- Set Group type to Bin, then choose a bin size or a bin count.
- Select OK. Power BI adds a new field named
ListPrice (bins).
Put the bin field on the X-axis of a column chart. Put a count of the product key in Values. This gives a quick histogram.
Fixed bin sizes are easy to set up. The limit is that the bin edges are numbers you pick. You cannot give the bins custom labels or control their order beyond the numeric sort.
Option 2: A DAX calculated column
A calculated column gives you labeled bands. This example uses the starter pattern from the topic plan.
Price Band =
SWITCH (
TRUE (),
Product[ListPrice] < 50, "Under 50",
Product[ListPrice] < 200, "50 to 199",
"200 and over"
)SWITCH ( TRUE (), ... ) tests each condition in order and returns the first label that matches. Because the conditions are checked top to bottom, each later band only needs its upper limit.
Next, build the chart:
- Add a clustered column chart.
- Put
Product[Price Band]on the X-axis. - Put
Product[ProductKey]in Values and set the aggregation to Count.
The chart shows how many products fall into each band.
Fix the band order
Text labels sort alphabetically. "200 and over" would appear before "50 to 199". To fix this, add a numeric sort column, for example Price Band Order with values 1, 2 and 3. Then select Price Band and, under Column tools, set Sort by column to Price Band Order.
Common errors
- Too many or too few bins. Two bins hide the shape. Fifty bins add noise. Try five to fifteen and adjust.
- Uneven bin widths. Bands such as "Under 50" and "200 and over" cover different ranges, so column heights are not directly comparable by range width. State this in the chart title or choose equal widths.
- Counting the wrong thing. A count of a non-key column skips blanks. Count a key column unless you want that behavior.
- Using a measure for the bin. Bins must come from a column, not a measure. A measure is calculated in the filter context of the visual, so it cannot define groups on an axis.
Exercise
A column chart of Price Band shows "200 and over" first, then "50 to 199", then "Under 50". Why, and how do you fix it?
Show answer
Text fields sort alphabetically, and "2" comes before "5" and "U". Create a numeric column such as Price Band Order (1, 2, 3) and set Price Band to Sort by column using that field.