Sub topic 5
Showing change over time with line and area charts
This chapter assumes you can build a basic report in Power BI Desktop and that your model has a fact table related to a date table. You should also know what a measure is and how the field wells work. Here you will learn when a line or area chart is the right choice for a trend question, how to set one up correctly, and which errors make time charts misleading.
When a trend question calls for a line chart
A trend question asks how a value changes across ordered time periods. Examples are "How have monthly sales moved this year?" and "Is support ticket volume rising?" The time axis is ordered and continuous in meaning, so the visual should show that order and the connection between adjacent points.
A line chart does this by joining points with segments. The slope of each segment shows the direction and speed of change. Bar and column charts are better for comparing separate categories. They are also acceptable for a few discrete periods, such as four quarters, but a line handles many periods more clearly.
| Visual | Best for | Weak at |
|---|---|---|
| Line chart | Many periods, several series, direction of change | Exact comparison of single periods |
| Area chart | One series where the magnitude of the total matters | Several overlapping series |
| Stacked area chart | Total over time with a few component series | Reading the exact size of any non-bottom series |
| Line and clustered column chart | A volume measure plus a rate or target on one axis pair | Too many series, which clutter the canvas |
Setting up the fields
A line chart needs a date or time field on the X-axis and one or more measures in Y-axis. An optional categorical field in Legend splits the line into one line per category.
The measure supplies the values:
Total Sales = SUM ( Sales[SalesAmount] )Use a column from your date table on the axis, not the date column from the fact table. A dedicated date table has no gaps and gives you year, quarter, month and day levels, and it is required for time intelligence functions.
Continuous and categorical axes
When you put a true date or datetime field on the X-axis, Power BI can treat the axis as continuous. Points are placed in proportion to the time between them, and gaps in the data appear as gaps in time. When you put a text field such as a month name on the axis, the axis is categorical. Points are spaced evenly no matter how much time passes between them.
You can switch the axis type under the X-axis format options by choosing Continuous or Categorical. Use these rules:
- Choose continuous when the dates are irregular or when spacing carries meaning.
- Choose categorical when every period is present and you want one evenly spaced tick per period, as with month names.
- If a month-name text field sorts alphabetically, as April, August, December, sort it by the month number column using Sort by column.
The date hierarchy
If you drag a date column from a table without a marked date table, Power BI may create an automatic date hierarchy with Year, Quarter, Month and Day levels. The chart then offers drill buttons. If you drag the hierarchy as a whole, the chart starts at the top level, year, and you drill down. This is often the cause of a line chart that shows only two or three points. Check which level you are on before you suspect the data.
Comparing with a prior period
A common trend request is to show this year against last year. The measure below supplies the comparison line:
Sales LY =
CALCULATE ( [Total Sales], SAMEPERIODLASTYEAR ( 'Date'[Date] ) )SAMEPERIODLASTYEAR needs a date table that is marked as a date table, or a date column that contains complete, contiguous dates. Without that, the measure returns wrong values or blanks.
Place both [Total Sales] and [Sales LY] in Y-axis and put 'Date'[Month] on the X-axis. You get two lines that share one month axis, so a reader can compare them directly. Give the prior-year line a lighter or dashed style so the current year stands out.
For a percentage change, use a ratio measure:
Sales YoY % =
DIVIDE ( [Total Sales] - [Sales LY], [Sales LY] )DIVIDE returns a blank rather than an error when [Sales LY] is zero or blank. This matters in the first year of data, where there is no prior year to compare against.
Line chart or area chart
An area chart is a line chart with the space under the line filled. The fill gives an impression of volume, so use it when the size of the quantity matters, such as cumulative revenue or inventory on hand. The fill also makes the baseline matter. An area chart should start at zero, because the filled region implies a quantity measured from the baseline. A line chart does not have to start at zero, since the reader judges slope and position, not area.
There are three area chart types:
- Area chart overlays series on a shared axis. Later series can hide earlier ones, so use it for one series or for series with clearly different ranges.
- Stacked area chart adds series on top of each other. The top edge shows the total, and each band shows one component. Only the bottom band has a flat baseline, so compare components with care.
- 100% stacked area chart shows each component's share of the total over time. It answers a composition-over-time question and hides the total.
Prefer the line chart when you have more than about three series or when the reader needs to compare individual values. Lines can cross without hiding each other, and fills cannot.
Choosing the granularity
The grain of the axis changes what the reader sees. Daily sales may look noisy, while monthly sales show the seasonal pattern. Choose the grain that matches the decision. A weekly operations review needs days. A board review of annual planning needs months or quarters.
- Too fine: noise hides the trend, and a chart with thousands of points becomes slow to render.
- Too coarse: spikes, outages and promotions disappear into the average.
- Mixed: do not compare a month that is only partly complete with full months. A partial last month looks like a collapse in sales.
For the partial-month problem, filter the visual to complete periods, or add a measure that returns a value only for completed months, so the line stops at the last full period.
Useful analytics features
Line charts have an Analytics pane that adds reference elements without extra DAX:
- Trend line fits a straight line to the data and shows the overall direction.
- Constant line marks a fixed target or threshold.
- Average line and Min/Max line mark summary values.
- Forecast extends a time series using seasonality detection. It needs a continuous date axis and enough history, so treat it as a rough aid and not as a planning model.
Some of these options are unavailable when the axis is categorical. If a feature is missing from the pane, check the axis type first.
Common mistakes
- Using a line for unordered categories. Joining points for regions or products suggests a progression that does not exist. Use a bar chart.
- Too many lines. More than five or six series become a tangle. Filter to the top few, highlight one, or use small multiples to split the chart into panels.
- Truncated area baseline. Starting an area chart above zero exaggerates change.
- Dual axes without labels. A line and column chart with two axes can imply a relationship that comes only from the scale choice. Label both axes and use it sparingly.
- Missing periods. On a categorical axis, a month with no rows can disappear, so the line connects its neighbors. Build the axis from the date table so every period is present.
- Treating blanks as zero. A measure that returns zero for periods with no data draws a false drop. Return a blank for periods that have no data, so the line stops.
Interaction and formatting notes
Selecting a point on a line chart cross-filters the other visuals on the page to that period. Selecting several points with Ctrl filters to several periods. Add tooltips that show the prior-year value and the percentage change, so the reader can get detail without extra series on the chart. For formatting, keep gridlines light, label the last point directly, and use color to separate the current series from context series. Later chapters cover sorting, labels, axes and color in more detail.
Exercise
Your line chart of monthly sales shows the prior-year line as blank for every month, although the model holds two years of data. The measure is Sales LY = CALCULATE ( [Total Sales], SAMEPERIODLASTYEAR ( 'Date'[Date] ) ). Name two likely causes and one fix for each.
Show answer
First, the X-axis may use the date column from the fact table, or the date table may be unmarked or may have gaps, so time intelligence cannot find the shifted dates. Fix this by building a complete, contiguous date table, marking it as a date table, and using its columns on the axis. Second, the relationship between the date table and the fact table may be missing or inactive, so the date filter never reaches Sales. Fix this by creating or activating a relationship on the date key.
Exercise
A stakeholder asks for a chart of cumulative revenue over the year, and another chart showing how five product lines contribute to revenue each month. Which visual type fits each, and what check should you do on the cumulative chart?
Show answer
Cumulative revenue suits an area chart, since the fill conveys accumulated volume, and its baseline should be zero. The five product lines fit a stacked area chart, or a line chart if readers need to compare individual lines, because five stacked bands make it hard to read non-bottom series. Confirm that the last month is complete and that the axis starts at zero.