Sub topic 8
Showing thousands and millions with commas
This chapter assumes you know how to open Format Cells, can tell a stored value from its display, and have written a basic custom format code with digit placeholders such as 0 and #. Here you will use the comma in two roles: as a thousands separator and as a scaling operator that shrinks what a cell displays.
Two jobs for one character
In a number format code, the comma does one of two things, and its position decides which.
- Between or before digit placeholders, it turns on the thousands separator.
#,##0shows 1234567 as 1,234,567. - Immediately after the last digit placeholder, it divides the displayed value by 1,000. Each trailing comma divides by another factor of 1,000.
The stored value never changes. Only the display is scaled, so a formula that refers to the cell still receives the full number.
Scaling to thousands
Start with the value 1234567 in a cell. Apply this custom format:
#,##0,The cell displays 1,235. The first comma is a separator because digit placeholders follow it. The last comma has no placeholder after it, so it scales. Excel divides 1,234,567 by 1,000, which gives 1,234.567, and then rounds to a whole number for display.
To add a label, put literal text in quotes after the scaling comma:
#,##0,"K"This shows 1,235K. Without the quotes, Excel may reject the code or interpret some letters as codes of their own, so quote any text you add.
Scaling to millions and billions
Two trailing commas divide by one million. The spine example keeps one decimal place:
0.0,,"M"With 1234567 in the cell, this displays 1.2M. Three trailing commas divide by one billion:
0.00,,,"B"With 1234567890, this displays 1.23B.
The table shows one stored value, 1234567, under several formats.
| Format code | Displayed result | What the commas do |
|---|---|---|
| `#,##0` | 1,234,567 | Separator only |
| `#,##0,` | 1,235 | Separator, then divide by 1,000 |
| `#,##0.0,` | 1,234.6 | Same, with one decimal |
| `#,##0,,` | 1 | Divide by 1,000,000 |
| `0.0,,"M"` | 1.2M | Divide by 1,000,000 and add a suffix |
| `0,"K"` | 1235K | Divide by 1,000, no separator |
Notice that #,##0,, shows 1 for a value of about 1.23 million. Scaling removes detail, so choose enough decimal places for your audience.
Applying a scaling format
- Select the cells that hold the full values.
- Press Ctrl+1 to open Format Cells.
- On the Number tab, choose Custom.
- Type the format code in the Type box, for example
0.0,,"M". - Check the Sample line, then select OK.
Do not type the code into the cell. The cell keeps the number you entered, and the format only changes how it looks.
Format versus division
You can get a similar look by dividing in a formula, such as =A1/1000000. The two approaches behave differently.
| Approach | Stored value | Sums and lookups use | Best for |
|---|---|---|---|
| Scaling comma in a format | Original (1234567) | Original value | Reports and dashboards where the data must stay exact |
| Dividing in a formula | Divided (1.234567) | Divided value | When the scaled number is the real quantity you need |
If you copy a formatted cell and paste it as values into another program, you get the full number, not the number as displayed. This surprises people who expect "1.2" and receive 1234567. Check where the data goes next before you rely on a scaled display.
Choosing the scale with conditions
A single scaling code applies the same divisor to every cell. If one column mixes small and large values, you can pick the scale per value with conditions in square brackets. A format can hold at most two conditions, plus a final section for everything else.
[>=1000000]0.0,,"M";[>=1000]0.0,"K";0This works as follows.
- A value of 1234567 matches the first condition and shows 1.2M.
- A value of 45600 matches the second and shows 45.6K.
- A value of 850 matches neither and falls through to the third section, so it shows 850.
Negative numbers are not greater than or equal to 1,000, so they fall into the last section and are not scaled. If your data has large negative values, this format will not shorten them. Keep that in mind before using it on profit and loss columns.
Rounding at the boundary also matters. A value of 999500 matches the second condition, and 0.0, rounds it to 999.5K. A value of 999999 shows 1000.0K, not 1.0M, because the value is below the million threshold. This is a known limit of the format approach. If it bothers you, use a helper column with a formula.
Regional settings change the character
The scaling character is the thousands separator of your regional settings. In English (US) settings, that is the comma. In settings where the thousands separator is a period, such as German (Germany), Excel shows the code with periods, for example 0,0.."M", and the scaling operator is the period. The behavior is identical, but the character you type differs. If a code copied from an English tutorial gives odd results on your machine, check your regional settings first. The locale chapter covers this in more detail.
Charts
Format codes also work on chart axes and data labels. In a chart, open Format Axis, go to Number, choose Custom, and enter #,##0,"K" in the Format Code box. You can also use the Display units option on the axis, which scales the axis and can add a label. A custom code gives more control over the suffix and decimals. Make sure Linked to source is cleared, or the chart will go back to the cell format.
Common mistakes
- Putting the comma before the digits.
,0.0is only a separator. The scaling comma must come after the last digit placeholder. - Forgetting the quotes. Write
"M", notM. Unquoted letters can be read as codes, andMis a month or minute code in date formats. - Expecting totals to change. A SUM of cells shown as
1.2Mstill adds the original values. - Expecting text. A scaled cell is still a number. Right-alignment and numeric sorting stay intact.
Exercise
A cell holds 8765432. Write a custom format that displays it as 8.8M, and say what the cell shows if you also add one more trailing comma to the code.
Show answer
Use 0.0,,"M". The two trailing commas divide the display by 1,000,000, which gives 8.765432, shown to one decimal as 8.8M. With a third comma, the display is divided by 1,000,000,000, giving 0.008765432, so the cell shows 0.0B if the suffix is changed to "B" or 0.0M if you keep the old suffix. The stored value stays 8765432 in all cases.
Exercise
You apply [>=1000000]0.0,,"M";[>=1000]0.0,"K";0 to a column. What does it show for 2500000, 45600, 850 and -3200000, and why does the last one look wrong?
Show answer
It shows 2.5M, 45.6K, 850 and -3200000. The negative value is not greater than or equal to either threshold, so it falls into the last section, which has no scaling comma and displays the full number.