Sub topic 5
Showing change over time with line and area charts
This chapter assumes you know the Power BI Desktop canvas, have a data model with a marked date table related to your fact table, and understand the measures from earlier chapters, such as [Total Sales].
Why line charts suit trends
A line chart plots a measure against a date/time field on the X-axis. The line connects points in time order, so the eye reads slope as speed of change and direction as growth or decline. Bar charts split time into separate blocks, which makes the overall shape harder to see when you have many periods.
Use a line chart when the question is "how has this changed?" or "is there a seasonal pattern?"
Building the visual
- Add a Line chart from the Visualizations pane.
- Put
'Date'[Date]in X-axis. Use the date hierarchy and drill down, or use a single field such as Month, depending on the grain you want. - Put
[Total Sales]in Y-axis. - Optionally, put a low-cardinality category in Legend to get one line per category.
Keep the Legend to about five lines. More than that produces a tangle that nobody can read.
Continuous or categorical axis
For a real date field, set the X-axis Type to Continuous so that gaps in time are spaced honestly. Choose Categorical only when you want each period shown as an equal-width label, such as "Jan, Feb, Mar" from a text column.
Comparing with the prior year
A second measure lets you compare the current period with the same period a year earlier. This measure needs a marked date table.
Sales LY =
CALCULATE ( [Total Sales], SAMEPERIODLASTYEAR ( 'Date'[Date] ) )Add [Total Sales] and [Sales LY] to the Y-axis of the same line chart. The two lines share one axis, so a gap between them is a real difference.
For a single percentage, use a measure on a card or KPI:
Sales YoY % =
DIVIDE ( [Total Sales] - [Sales LY], [Sales LY] )DIVIDE returns blank instead of an error when the prior-year value is zero or blank.
Area charts
An area chart is a line chart with the space under the line filled in. The fill emphasizes volume, or magnitude over time.
| Situation | Better choice |
|---|---|
| One or two series, trend is the point | Line chart |
| Cumulative total or volume matters | Area chart |
| Several series that add up to a whole | Stacked area chart |
| Many overlapping series | Line chart |
In a plain area chart, a series in front can hide one behind it. In a stacked area chart, only the bottom series sits on a common baseline, so the upper layers are hard to compare. If readers need to compare individual series, use lines.
Common errors
- Too many points or lines. Aggregate to month or week rather than plotting every day for years.
- Incomplete last period. A partial month shows a false drop. Filter it out or label it.
- Mixed grain. Comparing a daily line with a monthly line misleads readers.
- Missing date table. Time-intelligence functions like
SAMEPERIODLASTYEARreturn wrong results or errors without a marked date table.
Exercise
Your line chart shows Total Sales and Sales LY by month. The final point for Total Sales is far below Sales LY, but the current month is only half over. What is the likely cause, and how do you fix it?
Show answer
The last month is incomplete, so its total is compared with a full prior-year month. Filter the partial month out of the visual (for example with a visual-level filter on the date), or label it clearly as partial.