Sub topic 4
Comparing and ranking categories with bar and column charts
This chapter covers the built-in bar and column charts in Power BI Desktop. It assumes you can use the report canvas and have a data model with tables and relationships loaded. It also assumes you know basic aggregations such as sum, average and count, and that you have read the earlier chapters on field types, measures and starting from the question.
What these charts answer
Bar and column charts answer two related questions about categorical data:
- Comparison: how do categories differ in size? For example, sales by region.
- Ranking: which categories are largest or smallest? For example, the top ten products by revenue.
Both rely on the same visual encoding. The viewer compares the length of bars against a common baseline. People judge length against a shared baseline accurately, which is why these charts are the default answer to category questions.
The base measure used in this chapter is a simple sum:
Total Sales = SUM ( Sales[SalesAmount] )Bar or column?
A bar chart is horizontal. A column chart is vertical. They carry the same data, so the choice is about readability.
| Situation | Better choice | Reason |
|---|---|---|
| Long category names | Bar | Labels sit on the left and stay horizontal and readable |
| Many categories (more than about 7) | Bar | Report pages have more vertical room for a scrolling list |
| Ranking from largest to smallest | Bar | Top-to-bottom order is the natural reading order for a ranking |
| Few categories with short names | Column | Fits well in a compact space |
| Ordered categories such as age bands or size bands | Column | Left to right suggests low to high order |
| Time periods | Column, or a line chart | Left to right matches time, but see the trend chapter |
A useful rule: if you must rotate or truncate axis labels on a column chart, switch to a bar chart.
Visual types in the family
Power BI offers several variants. Pick by what you need to compare.
- Clustered bar or column: one bar per series within each category. Use it to compare a few series side by side, such as this year and last year by region.
- Stacked bar or column: series are stacked inside one bar per category. It shows totals well, but only the bottom segment shares a baseline, so other segments are hard to compare.
- 100% stacked bar or column: every bar is scaled to the same length, so it compares proportions. It hides absolute size.
For plain comparison and ranking, start with the clustered type and a single measure. Stacked types belong to composition questions, which a later chapter covers.
Building a ranked bar chart
Follow these steps in Power BI Desktop.
- Select Clustered bar chart in the Visualizations pane.
- Drag
Product[Category]into Y-axis. For a column chart, this field goes in X-axis instead. - Drag the
[Total Sales]measure into X-axis. In a column chart, it goes in Y-axis. - Open the visual's More options menu (the three dots), choose Sort axis, and pick Total Sales. Then choose Sort descending.
- Turn on Data labels in the Format pane so readers get exact values.
Dragging a numeric column such as Sales[SalesAmount] directly into the values well works, but Power BI applies an implicit aggregation. A named measure is more reusable and clearer. It also behaves the same in every visual that uses it.
Sort order is part of the message
A default bar chart often sorts alphabetically by category. That order suits lookup, not ranking. Sort by the measure when the question is "which is largest".
Keep a natural order when the categories have one. Months, weekdays and size bands should follow their own sequence, not value. If a text field such as month name sorts alphabetically (April, August, December), use Sort by column on the table to sort by a month number column. That setting is in the Data view or Table tools, and it affects every visual that uses the field.
Limiting a ranking to the top N
With many categories, a ranked chart becomes a long list. Use a Top N filter.
- Open the Filters pane and find the category field under Filters on this visual.
- Change Filter type to Top N.
- Set Show items to Top, enter a number such as 10, and drag your measure into By value.
- Select Apply filter.
Be explicit about what the filter hides. If the chart title says "Top 10 products" the reader knows the rest is excluded. Where the remainder matters, a common approach is to use a table or matrix for the full list and the bar chart for the headline view.
Showing share with a measure
Sometimes a ranking should show each category's share rather than its raw amount. Define a measure for share:
Sales % of Total =
DIVIDE (
[Total Sales],
CALCULATE ( [Total Sales], ALL ( Product[Category] ) )
)ALL ( Product[Category] ) removes the category filter inside CALCULATE, so the denominator is the grand total across all categories. DIVIDE returns blank instead of an error when the denominator is zero or blank. Format the measure as a percentage in the Measure tools ribbon. Use it as the value in a bar chart sorted descending to get a ranking by share.
A caution on the denominator: ALL ignores the category filter only. Other filters, such as a year slicer, still apply. That is usually what you want, because the shares then sum to 100% within the selected year.
Comparing two series
To compare actual against a prior period, add a second measure to the same chart. A clustered column chart then draws two bars per category. Define the prior-year measure like this:
Sales LY =
CALCULATE ( [Total Sales], SAMEPERIODLASTYEAR ( 'Date'[Date] ) )This requires a date table marked as a date table, with a continuous date column. When categories are not dates, such as regions, the date context comes from a slicer or the page filter, so the chart compares the selected period against the same period a year earlier.
A visual with two measures works for a few categories. With many categories, paired bars get cluttered. Consider a single measure for the difference instead:
Sales YoY % =
DIVIDE ( [Total Sales] - [Sales LY], [Sales LY] )Rank categories by Sales YoY % to answer "which region grew fastest". Check the absolute values too. A small region with a tiny base can show a large percentage change that means little.
Common errors
- Truncated axis. Bars encode value by length, so the value axis must start at zero. Under Format > Y-axis (or X-axis for a bar chart), check that the Start value is blank or 0. A non-zero start exaggerates differences.
- Alphabetical sorting for a ranking. This hides the order the reader needs. Sort by the measure.
- Too many categories. Beyond roughly 15 to 20 bars, use Top N, group small categories, or switch to a table.
- Stacked bars for comparison. Only the first segment is easy to compare. Use clustered bars when comparing a series across categories.
- A measure that sums something it should not. Summing a column like unit price gives a meaningless total. Choose the right aggregation, such as average, or write a measure that calculates it correctly.
- Blank category. A bar labeled "(Blank)" means some fact rows have no matching category, often a relationship or data quality problem. Fix it in the model instead of hiding it with a filter.
- Overlapping or hidden labels. Increase the visual's size, shorten category names in the model, or switch from column to bar.
Interaction behavior
Bar and column charts act as cross-filter sources by default. Selecting a bar filters other visuals on the page to that category. Ctrl+click selects several bars. Select the same bar again, or click empty space, to clear the selection. Selections are covered in detail in the interactivity chapter, but be aware now that a selected bar dims the others, which is useful for emphasis in a presentation.
Quick decision flow
Summary
Use a bar chart for ranking and for long labels. Use a column chart for few categories or ordered bands. Start the axis at zero, sort deliberately, label values, and limit the number of bars. Supply the values through named measures so every visual stays consistent.
Exercise
A column chart shows sales for 12 product subcategories. The category names are long and are rotated 45 degrees, and the bars appear in alphabetical order. The question is "Which subcategories sell the most?" List three changes you would make.
Show answer
(1) Switch to a clustered bar chart so the long names sit horizontally on the left. (2) Sort the axis by the Total Sales measure, descending, so the largest bar is at the top. (3) Check that the value axis starts at zero and turn on data labels so exact values are visible. Optionally, apply a Top N filter if more categories are added later.
Exercise
You build a clustered column chart of Sales YoY % by region. A small region shows +400% and tops the ranking. What is the risk, and how can you address it?
Show answer
The region may have a very small prior-year base, so a small absolute change produces a large percentage. Readers may over-weight it. Show the absolute values alongside, for example in a tooltip, a table, or a second chart of Total Sales and Sales LY, or filter out regions below a minimum sales threshold.