How to Use DATEPARSE in Tableau
Working with dates in Tableau can be tricky, especially when your data source formats them as text strings instead of actual dates. The DATEPARSE function is your best tool for converting those messy text strings into proper date fields that Tableau can understand and analyze. This article will walk you through exactly how DATEPARSE works, with clear step-by-step instructions and practical examples to fix your date fields for good.
What is the DATEPARSE Function?
The DATEPARSE function in Tableau converts a string (i.e., text) into a DATETIME data type. You use it when you have a field containing dates that Tableau doesn't recognize as a date, often indicated by the "Abc" icon next to the field name in the Data pane. When dates are stored as strings, you can't perform essential date operations like creating a time-series chart, drilling down from year to month, or calculating the time between two dates.
For example, if your data includes a column like "Invoice Submitted" with values like "01/15/2024" or "January 15, 2024," Tableau might interpret this as plain text. Using DATEPARSE, you can provide a "map" or a format that tells Tableau exactly how to read that text and understand it as a specific point in time.
This is different from other Tableau date functions:
- DATE(): This function converts a number, string, or date expression into a DATE data type. It's more of a general-purpose converter and can sometimes infer formats, but it lacks the precision of DATEPARSE.
- MAKEDATE(): This creates a date value from three separate number fields: year, month, and day. You would use this if you had columns for
[Order Year],[Order Month], and[Order Day]instead of a single string.
In short, when you have a single text field holding a full date or datetime that you need to convert, DATEPARSE is the most reliable and explicit function for the job.
Understanding the DATEPARSE Syntax
The syntax for the DATEPARSE function is straightforward, consisting of two parts:
DATEPARSE (format, string)
- format: This is a string literal where you define the structure of your date text. You use a specific set of symbols to represent parts of the date (like year, month, day). This must exactly match the structure of your data.
- string: This is the field in your data source that contains the date text you want to convert. It's usually a dimension from your data pane.
For an easy example, imagine you have a field named [Order Log Date] with text values like "03/25/2024". The correct formula to convert this would be a calculated field with the following:
DATEPARSE('MM/dd/yyyy', [Order Log Date])
In this formula, 'MM/dd/yyyy' is the format. It tells Tableau:
- Look for a two-digit month (MM)
- Then look for a forward slash (/)
- Next, look for a two-digit day (dd)
- Then a forward slash (/)
- Finally, a four-digit year (yyyy)
By providing this precise template, you eliminate any guesswork and ensure an accurate conversion.
Common Date and Time Format Symbols
The power of DATEPARSE comes from knowing which symbols to use in your format string. Getting these right is the key to making the function work. The symbols are case-sensitive, so MM (month) is different from mm (minute).
Date Symbols
yyyy: Four-digit year (e.g., 2024)yy: Two-digit year (e.g., 24)MMMM: Full month name (e.g., January)MMM: Three-letter abbreviated month name (e.g., Jan)MM: Two-digit month number (01 to 12)dd: Two-digit day of the month (01 to 31)dorD: One- or two-digit day of the month (1 to 31)EEEEordddd: Full weekday name (e.g., Monday)
Time Symbols
HH: Hour in day (0-23 for a 24-hour clock)hh: Hour in AM/PM (1-12 for a 12-hour clock)mm: Minute in hour (0-59)ssorSS: Second in minute (0-59)aoraa: AM/PM marker
Remember, any separators in your text—like dashes (-), slashes (/), spaces, commas, or colons (:)—must also be included in your format string in the exact same positions.
A Step-by-Step Guide to Using DATEPARSE in Tableau
Let's walk through the process of creating a DATEPARSE calculation in Tableau Desktop.
Step 1: Identify Your Text Date Field
In the Data pane on the left, locate the field that contains your date text. You'll know it's a string field if it has an "Abc" icon next to its name.
Step 2: Create a New Calculated Field
Right-click on your text date field (or anywhere in the blank space of the Data pane) and select Create > Calculated Field...
Step 3: Write Your DATEPARSE Formula
A dialog box will open. First, give your new field a descriptive name, like "Signup Date (Formatted)." Then, in the large text area, type your formula. Let's say your source field is named [start_date] and an example value is 2023-04-16.
Your formula would be:
DATEPARSE('yyyy-MM-dd', [start_date])
As you type, Tableau provides helpful tips. At the bottom of the dialog, a message will appear: "The calculation is valid." If there's a syntax error, it will immediately flag it.
Step 4: Change the Data Type
After creating the field, Tableau will assign it a Datetime data type (with a calendar and clock icon). If you don't need the time component, you can left-click on the icon and change its data type to Date.
Step 5: Use Your New Date Field
You will now see your new field, "Signup Date (Formatted)," in the Data pane with a calendar icon. You can drag this field into your view (e.g., onto the Columns shelf), and Tableau will recognize it as a date, allowing you to use date hierarchies and other time-based features.
More DATEPARSE Examples for Common Scenarios
Here are a few more real-world examples to help you handle different types of date strings.
1. Handling Full Month Names and Commas
Suppose your date strings look like this: "March 15, 2024". The format needs to account for the full month name, the space, and the comma.
- Sample String: "March 15, 2024"
- Formula:
DATEPARSE('MMMM dd, yyyy', [Date String])
2. Parsing Datetime Strings with AM/PM
When you have time information included, make sure to use the correct symbols for hours (hh vs. HH) and the AM/PM designator (a).
- Sample String: "03/15/2024 02:30:10 PM"
- Formula:
DATEPARSE('MM/dd/yyyy hh:mm:ss a', [Datetime String])
3. Parsing European or DD/MM/YYYY Formats
A very common source of confusion is the day/month order. DATEPARSE makes it easy to handle this as long as you specify the format correctly.
- Sample String: "15/03/2024"
- Formula:
DATEPARSE('dd/MM/yyyy', [Date String])
Troubleshooting: What to Do When DATEPARSE Returns Null
The single most common problem with DATEPARSE is that it returns Null (blank) values. This almost always means something is wrong with your format string.
Problem: The Format Doesn't Match the String
If even one character is off, the function will fail. Look closely at your data and check for these common mistakes:
- Incorrect Separators: Using a
/in your format for data that has a-. - Wrong Date Part Symbol: Using
Mfor month when it should beMMfor a two-digit month. - Mismatched Case: Using
mm(minutes) when you have a monthMM.
The Fix:
Put your source data string side-by-side with your DATEPARSE formula. Go character by character—date part, separator, date part, separator—and make sure your format string is a perfect blueprint of your data string.
Problem: Inconsistent Formats in a Single Column
Sometimes a single column contains dates in multiple formats (e.g., some are "03/15/2024," while others are "15-Mar-2024"). DATEPARSE can't handle this on its own. The best solution is to clean this data before it gets to Tableau using a tool like Tableau Prep or another ETL process. If that's not possible, you might need to build a more complex calculation using string functions like IF CONTAINS() or REGEXP_MATCH() to identify the format of each row and apply the correct DATEPARSE function, but this can become complicated and slow down your workbook.
Final Thoughts
The DATEPARSE function is a powerful and essential tool in your Tableau toolkit for converting pesky text strings into usable date fields. By creating a format string that precisely matches your data's structure, you can unlock Tableau’s full range of date-based analysis, enabling everything from simple time-series charts to complex period-over-period calculations.
Manually building calculations like this for every data source still takes time, especially when you need to answer a quick business question. That's why we built Graphed. Instead of wrestling with syntax, calculated fields, and troubleshooting, you can connect your data sources and simply ask for what you need in plain English, like "Show me revenue by week for the last quarter." We handle all the data formatting and complex functions automatically, allowing you to go from raw data to a real-time dashboard in seconds.
Related Articles
How to Enable Data Analysis in Excel
Enable Excel's hidden data analysis tools with our step-by-step guide. Uncover trends, make forecasts, and turn raw numbers into actionable insights today!
What SEO Tools Work with Google Analytics?
Discover which SEO tools integrate seamlessly with Google Analytics to provide a comprehensive view of your site's performance. Optimize your SEO strategy now!
Looker Studio vs Metabase: Which BI Tool Actually Fits Your Team?
Looker Studio and Metabase both help you turn raw data into dashboards, but they take completely different approaches. This guide breaks down where each tool fits, what they are good at, and which one matches your actual workflow.