How to Extract Year from Date in Tableau

Cody Schneider••9 min read

Working with dates in Tableau is essential for almost any kind of analysis, but sometimes you just need to isolate a single part, like the year. Pulling the year out of a date field allows you to compare performance year-over-year, filter dashboards, or create clean, simple labels. This guide will show you several straightforward methods for extracting the year from a date in Tableau, making your data analysis cleaner and more powerful.

GraphedGraphed

Build AI Agents for Marketing

Build virtual employees that run your go to market. Connect your data sources, deploy autonomous agents, and grow your company.

Watch Graphed demo video

Why Single Out the Year?

Before jumping into the "how," it helps to understand the "why." Extracting the year from a full date like '10/23/2023' into a simple '2023' is a fundamental step for many types of business reporting. Imagine you're a marketing manager looking at your Google Analytics data, you need to see if your website traffic is growing consistently. A perfect way to do this is to compare this year's traffic to last year's.

Here are a few common scenarios where extracting the year is a critical first step:

  • Year-over-Year (YoY) Growth: Calculating YoY growth in sales, website sessions, or lead conversions is impossible without first isolating the year for comparison.
  • Filtering and Parameters: You might want to build a dashboard where users can select a specific year from a dropdown menu to filter all the charts on the view. This requires a dedicated "Year" field.
  • Creating High-Level Summaries: When showing a long-term trend, displaying every single date on an axis can look messy. Grouping data by year provides a cleaner, high-level view of your performance over time.
  • Grouping and Labeling: You can use the year as a category to group data, such as segmenting customers by the year they first made a purchase from your Shopify store.

Essentially, extracting the year transforms a granular piece of data into a powerful dimension for aggregation, comparison, and visualization.

Method 1: Create a Calculated Field with Date Functions

The most flexible and powerful way to extract the year is by creating a calculated field. This creates a new, reusable field in your data pane that contains only the year. Tableau provides a couple of simple functions for this: YEAR() and DATEPART().

Both functions return the year as a number (an integer), which is perfect for use in subsequent calculations or as a filter.

Free PDF · the crash course

AI Agents for Marketing Crash Course

Learn how to deploy AI marketing agents across your go-to-market — the best tools, prompts, and workflows to turn your data into autonomous execution without writing code.

Using the YEAR() Function

The YEAR() function is the most direct and common method. Its job is simple: take a date and return the four-digit year as an integer.

Let's say you have a field named [Order Date] and you want to extract the year. Here’s how you’d do it step-by-step:

  1. In your Tableau worksheet, right-click on an empty area in the Data pane (the left-hand sidebar) and select "Create Calculated Field."
  2. A dialog box will open. Give your new field a descriptive name, like "Order Year."
  3. In the formula box, type the following:
YEAR([Order Date])

Make sure to replace [Order Date] with the actual name of your date field.

The calculation editor will tell you "The calculation is valid." Click "OK."

That's it! You'll now see your new "Order Year" field in the Data pane under Measures. You can drag it into your view just like any other field. Because it's a number, Tableau might default to treating it as a measure (and try to sum it), but you can easily convert it to a dimension by dragging it to the Dimensions section or right-clicking and selecting "Convert to Dimension."

Using the DATEPART() Function

The DATEPART() function is a more versatile tool that can extract various parts of a date (like 'quarter', 'month', 'day', or 'weekday'), including the year.

The syntax looks like this:

DATEPART('year', [Your Date Field])

Here’s how you'd apply it:

  1. Create a new Calculated Field as described before. Name it something like "Transaction Year."
  2. In the formula editor, enter the following calculation:
DATEPART('year', [Transaction Date])

Again, replace [Transaction Date] with your date field. The first part, 'year', must be in lowercase and enclosed in single quotes. This part of the formula tells Tableau which date part you want to extract.

YEAR() vs. DATEPART('year'): Which Should You Use? For simply extracting the year, both functions produce the same result — an integer representing the year. The YEAR() function is slightly cleaner and more direct since that's its only purpose. DATEPART() is the better function to remember if you plan on extracting other date parts frequently, as it uses a consistent syntax for everything.

Method 2: Using Tableau's Built-in Date Hierarchies

What if you don't want to create a whole new calculated field? Sometimes, you just want to quickly see your data aggregated at the yearly level. Tableau’s drag-and-drop interface makes this incredibly simple.

When you use a date field in Tableau, it automatically comes with a built-in hierarchy: Year > Quarter > Month > Day. You can use this to your advantage.

GraphedGraphed

Build AI Agents for Marketing

Build virtual employees that run your go to market. Connect your data sources, deploy autonomous agents, and grow your company.

Watch Graphed demo video

Step-by-step instructions:

  1. Drag your date field (e.g., [Order Date]) onto the Columns shelf. By default, Tableau will likely display it as "YEAR([Order Date])". You'll see a blue pill with the year values (e.g., 2021, 2022, 2023).
  2. Now, drag a measure, like [Sales], onto the Rows shelf. Tableau will automatically generate a line chart showing total sales for each year.

Notice the pill on the Columns shelf. It says YEAR([Order Date]). If you click the small "+" symbol on this pill, Tableau will drill down to the next level in the hierarchy: Quarter. Click it again, and you’ll get to Month. The "-" symbol lets you drill back up.

This method is fantastic for quick exploration and visualization because in a single click, you can switch from a yearly view to a quarterly or monthly view without writing any calculations.

Method 3: Understanding Discrete vs. Continuous Dates (Blue vs. Green)

This is where Tableau's power really shines, and understanding it will prevent a lot of headaches. In Tableau, date values can be either Discrete (blue pills) or Continuous (green pills).

  • Discrete (Blue): Treats dates as distinct categories or headers. For example, using YEAR([Order Date]) as a discrete value will give you separate columns for "2022," "2023," and "2024." It breaks down the data.
  • Continuous (Green): Treats dates as points along an unbroken timeline. Using YEAR([Order Date]) as a continuous value places years on a quantitative axis, allowing you to see a trend over time from the beginning of 2022 to the end of 2024.

The "drill-down" method described above defaults to using discrete years. But you can easily switch between different date parts and choose whether they are discrete or continuous.

A Handy Trick for Choosing Your Date Part

Instead of just left-click-dragging your date field, try this:

  1. Right-click and drag your date field (e.g., [Order Date]) to the Columns or Rows shelf.
  2. When you release the mouse button, a context menu will pop up, giving you a list of options.
  3. You will see two sections. The top section (with dates like "May 8, 2015") corresponds to continuous dates (green pills). The bottom section corresponds to discrete date parts (blue pills).

From this menu, you can directly select "YEAR([Order Date])" from the top section for a continuous axis or "Year" from the bottom section for discrete headers. This right-click-drag method is a massive time-saver and gives you precise control over how you want your dates to be displayed and analyzed.

Troubleshooting: What if Your Date Field Isn't a Date?

A common problem is when your data source has dates formatted as text strings (e.g., "2023-11-05" or "11/05/2023"). When this happens, Tableau won't recognize it as a date, and the date functions like YEAR() will throw an error.

You can identify a text field by the "Abc" icon next to it in the Data pane. A proper date field will have a calendar icon.

To fix this, you have two options:

Free PDF · the crash course

AI Agents for Marketing Crash Course

Learn how to deploy AI marketing agents across your go-to-market — the best tools, prompts, and workflows to turn your data into autonomous execution without writing code.

1. Change the Data Type

The easiest fix is to try changing the data type directly.

  • In the Data pane, click the "Abc" icon next to your field name.
  • From the dropdown menu, select "Date" or "Date & Time."

If Tableau is able to recognize the format, it will automatically convert the field. If not, you'll need to use a calculation.

2. Use the DATEPARSE() or DATE() Function

For more complex text formats, the DATEPARSE() function is your best friend. It lets you tell Tableau exactly how your text-based date is formatted.

For example, if your date string is formatted as "2023-10-23", your calculated field would be:

DATEPARSE('yyyy-MM-dd', [Your String Date Field])

If your date string looks like "10/23/23", it would be:

DATEPARSE('MM/dd/yy', [Your String Date Field])

Once you have a calculated field that correctly parses the string into a real date, you can wrap it inside the YEAR() function, all in one step:

YEAR(DATEPARSE('yyyy-MM-dd', [Your String Date Field]))

This combined formula first converts your text into a date and then immediately extracts the year from it, solving the problem in a single calculated field.

Final Thoughts

Getting the year from a date field is a foundational skill in Tableau, and mastering it unlocks deeper levels of analysis, from simple trend lines to complex YoY performance metrics. Whether you use a direct YEAR() calculation, leverage the right-click drag menu for speed, or need to fix text-based dates first with DATEPARSE(), you now have the tools to handle almost any scenario.

We believe data analysis shouldn’t require you to become an expert in formula syntax or complex BI tools. As you become more comfortable with these steps, you'll find there are even faster ways to get answers. At Graphed, we’ve made this process as simple as asking a question. Instead of writing calculations, you can connect your data sources like Google Analytics or Salesforce and instantly ask things like, “show me our annual sales trend,” and get a live, interactive chart in seconds.

Related Articles