Sub topic 4
Showing magnitude with data bars
Data bars draw a horizontal bar inside each cell. The bar's length reflects the cell's value compared with the other values in the range. This chapter assumes you can select ranges, apply basic cell formatting, and open the Conditional Formatting menu on the Home tab. You do not need formula-based rules yet, although the last section touches on them.
What data bars do
A data bar is a conditional formatting rule that fills part of a cell with color. A larger value gets a longer bar. You can compare a column of numbers at a glance without reading each one.
Data bars suit these tasks:
- Comparing sales, quantities, or scores across rows.
- Spotting the largest and smallest values in a list.
- Adding a visual layer to a table without creating a chart.
They are a poor fit when the values are nearly identical, when the range has extreme outliers, or when you need exact comparisons. The bar shows relative size only.
Applying a data bar
- Select the numeric cells, for example
B2:B13. - On the Home tab, choose Conditional Formatting.
- Point to Data Bars.
- Pick a Gradient Fill or Solid Fill color.
Excel draws the bars at once. The cell value stays visible on top of the bar.
The sample data below is used in the rest of the chapter. Paste it into A1:B13.
import csv
rows = [
("Region", "Net change"),
("North", 4200),
("South", 1800),
("East", -950),
("West", 3100),
("Central", 0),
("Coast", 7600),
("Valley", -2300),
("Plains", 560),
("Lakes", 2750),
("Hills", -120),
("Delta", 5100),
("Desert", 880),
]
with open("net_change.csv", "w", newline="") as f:
csv.writer(f).writerows(rows)
print("Wrote", len(rows) - 1, "data rows to net_change.csv")Open net_change.csv in Excel, select B2:B13, and apply a data bar. Column B contains positive, zero, and negative values, which shows how data bars handle each case.
Gradient fill versus solid fill
Gradient fill fades the color toward the right end of the bar. Solid fill uses a single flat color.
| Feature | Gradient fill | Solid fill |
|---|---|---|
| Look | Fades toward the bar end | Flat color |
| Border | None by default | Border available |
| Readability when bars fill the cell | Text stays clearer | Text can be harder to read |
| Best for | Light, quick comparisons | Printing and screenshots |
Solid fill with a lighter color usually prints better. Dark solid bars can hide dark text.
How Excel sizes the bars
By default, Excel sets the shortest bar from the lowest value and the longest bar from the highest value in the range. Each value in between is placed proportionally.
This default produces a common surprise. If your values are 95, 96, 97, and 98, the smallest is 95. Its bar is very short and the largest bar is full length. The data looks far more different than it is.
The Excel setting that controls this is the Minimum and Maximum type for the rule. You change it in the rule editor.
Editing the rule
- Select any cell that has the data bar.
- Choose Conditional Formatting, then Manage Rules.
- Select the data bar rule and choose Edit Rule.
The dialog has these main parts:
- Show Bar Only hides the number and leaves just the bar.
- Minimum and Maximum each have a Type and a Value.
- Bar Appearance sets fill, color, and border.
- Negative Value and Axis opens settings for negative numbers.
- Direction chooses left to right, right to left, or context.
Minimum and maximum types
| Type | Meaning |
|---|---|
| Lowest Value / Highest Value | Uses the smallest or largest value in the range. This is the default. |
| Number | Uses a fixed number you type. |
| Percent | Uses a percentage of the range between lowest and highest. |
| Percentile | Uses a percentile of the values. This limits the effect of outliers. |
| Formula | Uses the result of a formula, such as a cell reference. |
| Automatic | Lets Excel choose. A minimum of zero is used when all values are positive. |
Here are three uses.
- Set Minimum to Number
0so a bar starts at zero. The bar lengths then match the true ratio between values. A value of 50 is half as long as a value of 100. - Set Maximum to Number
100for percentage scores. Every bar then uses the same scale, even if no cell reaches 100. - Set Maximum to Percentile
90so one huge value does not shrink every other bar. Values above the cutoff get a full bar.
Using a cell as the limit
With the Formula type, you can point to a cell. Suppose E1 holds a target of 5000. Set Maximum to type Formula with value =$E$1. Each bar then shows progress against the target, and a cell at 5000 gets a full bar.
Use an absolute reference such as $E$1. A relative reference may shift in unwanted ways. Chapter 9 covers references in detail.
Negative values and the axis
Data bars handle negatives in a separate way. The bar for a negative value grows to the left of an axis, and positive bars grow to the right.
Open Edit Rule, then Negative Value and Axis. There you can set:
- Fill color for negative bars, red by default.
- Border color for negative bars.
- Axis position: Automatic, Cell midpoint, or None.
- Axis color.
The axis position matters:
| Axis setting | Result |
|---|---|
| Automatic | The axis moves to match the proportion of negative values. |
| Cell midpoint | The axis is always at the center of the cell. |
| None (show negative bars in the same direction as positive) | Negative values are drawn as positive bars. Avoid this unless you have a reason. |
With Automatic, the axis position depends on your data. In the sample column, the smallest value is -2300 and the largest is 7600. The axis sits about a quarter of the way in from the left, since negatives take up that share of the total span. Cell midpoint gives the negative side as much room as the positive side, which makes negative bars look longer than they are in proportion.
Zero values show no bar. The cell B6 with value 0 has an empty bar and sits on the axis.
Using Show Bar Only
Show Bar Only hides the number. It works well for dashboards, where the bar is the message. Use it with care. Readers cannot recover the exact value from a bar, so keep the numbers elsewhere, such as in an adjacent column, if they matter.
A common pattern is to put the same data in two columns. One column shows the numbers. The other column holds =B2 formulas with a data bar set to Show Bar Only.
=B2Fill that formula down alongside the data, then apply the data bar rule to the new column.
Data bars and the Applies to range
The data bar compares cells only within the range it applies to. If you apply separate rules to B2:B7 and B8:B13, each half is scaled by its own lowest and highest values. A bar in the top half may then look the same length as a bar in the bottom half that has a very different value.
To compare all the rows, apply one rule to the whole range B2:B13. You can check this in the Rules Manager. The Applies to column should show a single range.
Common problems
- All the bars look the same length. The values are close together and the minimum is set to Lowest Value. Set Minimum to Number 0, or the bars exaggerate tiny gaps.
- One bar is full and the rest are tiny. An outlier sets the maximum. Use Percentile for the Maximum.
- No bars appear. The cells contain text that looks like numbers. Convert them to numbers. Data bars ignore text.
- Bars from two groups cannot be compared. Each rule scales to its own range. Use one rule over the full range.
- Error values break the rule. If the range contains
#N/Aor another error, data bars do not draw for the range. Wrap the source formulas withIFERRORor remove the errors. - Bars look the same on a printed page. Light gradient colors can print poorly in grayscale. Use a darker solid fill and a border.
Data bars compared with other options
| Option | Best for | Limitation |
|---|---|---|
| Data bars | Comparing magnitude within a column | Needs one numeric range and cell width |
| Color scales | Showing distribution across a range | Hard to read exact differences |
| Icon sets | Putting values into categories | Shows categories only, not size |
| Chart | Detailed comparison and labels | Lives outside the cell |
Data bars are the right choice when you want a quick visual comparison next to the numbers, with no extra object on the sheet.
Exercise
A column holds the values 92, 94, 95, and 97. You apply a default data bar. The bar for 92 is nearly empty, and the bar for 97 is full. How do you make the bars reflect the true ratio between the values, and what do you expect to see afterward?
Show answer
Edit the rule and set Minimum to type Number with value 0. Excel then scales bars from zero, so every bar is a similar length: 92 is about 95 percent of the length of 97. The earlier large difference came from using the lowest value as the minimum.
Exercise
You apply one data bar rule to B2:B7 and another to B8:B13. A value of 4000 in the first range has a bar the same length as a value of 900 in the second range. Why does this happen, and how do you fix it?
Show answer
Each rule scales its bars to the lowest and highest values in its own Applies to range, so the longest bar in each range is full length. To fix it, delete the two rules and apply one rule to B2:B13. In the Rules Manager, the Applies to column should then show =$B$2:$B$13.
Exercise
A progress column holds values from 0 to 4800, and the target is 5000 in cell E1. How do you set up a data bar so that a value of 5000 would fill the cell completely?
Show answer
Edit the data bar rule, set Minimum to Number 0, and set Maximum to type Formula with value =$E$1. The absolute reference keeps the limit fixed on E1, so a value of 5000 gets a full bar and 2500 gets a half bar.