1

I'm trying to create an Excel line chart that would dynamically present the following data (this is just a sample, the data set is much bigger and is changing a lot):

Name | Salary change date | Salary --------------------------------------- John Doe | 02/01/2021 | $3,500 John Doe | 07/01/2021 | $3,700 Lucy Liu | 05/05/2020 | $3,900 Lucy Liu | 08/07/2021 | $3,950 

I'd like to have a line chart with multiple series, where each series is one person, and on a horizontal axis there's time, while on vertical axis there's salary, so that I can see all people's salaries over time.

I tried two approaches: both a classical line chart, and a pivot table + pivot chart combination. The former I can't get to work at all somehow. The latter almost works, but I only managed to get this working for a data set in which all dates for John Doe are earlier in time than any of the dates for Lucy Liu, but this obviously doesn't solve my issue.

(The exact version I'm running is Version 2202 Build 16.0.14931.20128 - I'm assuming it's Microsoft Excel 2016.)

2
  • What is the question, exactly? Why does using a line chart not work? What is your expected result? Commented Mar 28, 2022 at 15:14
  • In my opinion, I would suggest you use filter to show the salaries for each people, as the date for each people is different. If all people use one date axis at the same time, the chart will be easy to be confusion. Commented Mar 29, 2022 at 8:40

1 Answer 1

3

The main challenge in most Excel charting questions is getting your data arranged so that Excel can create the chart you want. In your case you want:

  • horizontal axis to show date (not time-an important distinction)
  • vertical axis to show salary values
  • each line (series) to show a single individual's salary

First, make sure your dates are actually dates in Excel.

dates

Next rearrange your data so that each line (series) is in a single column (or row). The easiest way to accomplish this is to create a Pivot Table. Change your data into a Table Insert > Table

table

Then, use that Table as a source for your Pivot Table, Insert > Pivot Table, with

  • Columns = Name
  • Rows = Salary Change Date
  • Values = Sum of Salary

pivot table

From here, you can create a Pivot Chart (a special chart tied to Pivot Tables), and it will look something like this:

pivot chart

There are two major problems: the lack of line between Lucy's data points and the inconsistent spacing of the date points.

To correct the gap, you'll need to adjust the chart's Hidden and Empty Cells setting, found in the Select Data Source dialog box. It defaults to Gaps and you need to change it to Connect data points with line.

no gaps

The other problem is more challenging. In a Line Chart, Excel displays the Horizontal Axis as a categorical axis-meaning that each entry is given the same weight. So even though there's 8 months between your first and second dates (2020-05-05 and 2021-02-01), and 5 months between your second and third dates (2021-02-01 and 2021-07-01), there's the same distance along the horizontal axis-1 tick each.

To correct this, you need to pad your data with empty date values (to the Month level, if that's close enough, or to the Date level if it's critical). The resulting Table and Pivot Table might look like this:

blanks

And the Chart would look like this:

chart with padded dates

A better option is to use an XY/Scatter Chart (because both Axis values are displayed as Continuous data, which is better for dates in your context). Unfortunately, Pivot Charts cannot use an XY/Scatter Chart type. You can still use your Pivot Table as your data source, you just need to do it manually.

  1. Select a blank cell
  2. Insert > Charts > Scatter > Scatter with Straight Lines and Markers
  3. For each data series, manually set:
  • Series Name = Pivot Table Column Label
  • Series X = Pivot Table dates
  • Series Y = Pivot Table sum of salary values for applicable column
  1. Adjust Hidden and Empty Cells settings as above

And your chart should look like this:

xy chart

It's nearly identical to the Pivot Chart, without the need for additional padded values and the resulting Blank series.

1
  • 1
    Thanks @dav! That's an excellent answer, addressing all my doubts. The Hidden and Empty cells was exactly what I was missing - that's why in my original question I said that I only managed to get this working for sorted data. Your solution addresses this and also the yet un-asked problem related to spacing the dates evenly! Amazing. Commented Mar 30, 2022 at 13:57

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.