Displaying Month and Year on the X-axis in a Google Sheets Chart

Currently, you can display both month and year together on the X-axis in a Google Sheets chart, but what if you want to display them separately?

This requires a multiple-category feature, which Google Sheets currently lacks. However, there is a workaround, different from what you might have experienced in Excel.

To display month and year on the X-axis, we aim to use years as the main category and months as sub-categories. The workaround outlined below should address this need to some extent.

Displaying Month and Year Together

Let’s first see how Google Sheets handles month and year on the X-axis.

Assume I have the monthly gasoline consumption by a fleet of trucks (fleet fuel spending data) in our company for the last two years in columns A and B.

A2:A25 contains the beginning of the month dates such as 1/1/2018, 1/2/2018, …, 1/12/2019 formatted to “MMM-YYYY” (Format > Number > Custom Number Format > mmm-yyyy)

B2:B25 contains the quantity in gallons.

Monthly gasoline consumption data for column chart

I can plot a column, bar, line, etc., graph with this data type in Google Sheets.

Here I am going to create a column chart, which is more common in such types of visualizations.

In that chart, the category axis (X-axis) will contain the month and year values. But it will be cluttered as below.

Column chart displaying cluttered month and year names

This is the typical way of displaying the month and year in a column chart. Here, you can see that the X-axis is crowded with values, making it somewhat cluttered. How can this be resolved?

Before explaining how to display the month and year separately on the X-axis, let’s examine the chart settings of the above column chart.

To create the chart, select the data range and navigate to the menu Insert > Chart. This action will insert a chart and open the chart editor in Sheets.

Below are the chart editor settings that you should follow under the “Setup” tab to create the aforementioned column chart.

Essential Column Chart Settings Related to Monthly Data:

  • Chart type: Column
  • Stacking: None
  • Data range: A1:B25
  • X-axis: A1:A25 (by default you will see the field label)
  • Series: B1:B25 (by default you will see the field label)
  • Check Mark Against:
    • Use row 1 as headers
    • Use column A as labels
    • Treat labels as text.

The Workaround to Display Month and Year on the X-axis in Sheets

First of all, let’s see what the chart will look. I think it’s clutter-free compared to the above column chart.

Displaying month and year separately on a column chart

Here, the categories are the years, and the month names are the sub-categories, displayed as axis labels.

Do you like this chart? Then read on to understand how to plot it.

The crucial aspect of this workaround is restructuring the source data. For that, you can use formulas or manual methods.

To plot the above column chart, the data should resemble the format below. Only then can we display the month and year on the X-axis in a clutter-free manner.

Splitting month and year for use in a chart

Step-by-Step Instructions to Format the Source Data for the Chart

I am using a few basic formulas to format the data. See the modified data in columns D, E, and F. You can use formulas to format the data as below.

First, enter the labels in the header row D1:F1. Then use the following formulas:

In cell D2:

=MAP(A2:A25, LAMBDA(v, IF(IFERROR(YEAR(v)<>YEAR(OFFSET(v, -1, 0)), YEAR(A2)), YEAR(v),)))

The MAP function iterates over each value in the array A2:A25 to execute the following unnamed lambda function.

IF(IFERROR(YEAR(v)<>YEAR(OFFSET(v, -1, 0)), YEAR(A2)), YEAR(v),)

This formula tests if the year of the date in the current row of the array is not the year of the date in the previous row. If it evaluates to TRUE, the formula returns the year.

The formula will evaluate to an error in the first row of the array because of the text value in the previous row. The IFERROR removes that error and returns the year of the date in the first row of the array.

In cell E2:

=ArrayFormula(TEXT(A2:A25, "mmm"))

Returns the month text.

In cell F2:

={B2:B25}

This simply copies the values from column B to column F.

Chart Editor Settings to Display Month and Year on the X-axis

Here are the chart settings that I have followed:

  • Chart type: Column
  • Stacking: None
  • Data range: D1:F25
  • X-axis: D1:D25 (by default, you will see the field label “Year”; if not, remove the existing label and select “Year”)
  • Label: E1:E25 (Month)
  • Series: F1:F25 (by default, you will see the field label)

If you encounter difficulties following the points above to set the axis, please review the axis settings again.

Settings to display month and year on the x-axis

Resources

Here are some resources related to customizing column charts in Google Sheets.

Prashanth KV
Prashanth KV
Your Trusted Google Sheets and Excel Guide Prashanth KV brings a wealth of experience in Google Sheets and Excel, cultivated through years of work with multinational corporations in Mumbai and Dubai. As a recognized Google Product Expert in Docs Editors, Prashanth shares his expertise through insightful blogging since 2012. Explore his blog for practical tips and guidance on maximizing your spreadsheet skills.

Lookup Previous Values Dynamically in Excel and Google Sheets

Sometimes, you may want to look up the previous values relative to the current...

Sort Data but Keep Blank Rows in Excel and Google Sheets

Using a dynamic array formula or the FILTER command, we can sort data and...

Lookup Values Under Categories in Excel and Google Sheets

We can use a combination of XLOOKUP and VLOOKUP in both Excel and Google...

Extract Items Under a Category from the Same Column in Excel

In Excel, you can use a combination of the XLOOKUP and DROP functions to...

More like this

XMATCH Row by Row: Finding Values Across a Range in Google Sheets

Using the BYROW function with XMATCH in Google Sheets allows us to match values...

Limit Formula Expansion to a Specific Row in Google Sheets

In this tutorial, I’ll explain how to limit the expansion of an array formula...

3-D Referencing Structured Data Tables in Google Sheets

When you have several tables within a single sheet—not across multiple sheets in a...

2 COMMENTS

  1. Is there a way to move the x-axis, which displays the months, to the bottom of the graph? It looks aesthetically unpleasing positioned in the middle of the chart, but I haven’t found a way to relocate it. Thank you.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.