Power Query Date.FromText: Step-by-Step Guide
In this article
The Date.FromText function in Power Query converts a text value into a date. It is the go-to tool when your source data stores dates as text—common with CSV imports, Excel cells formatted as text, or data pulled from web pages. The function reads the text, interprets it according to the locale and format you specify (or the default), and returns a proper date value that you can then use in calculations, filters, and relationships. Before you start, you need Power Query available—either in Excel (Data > Get & Transform Data) or in Power BI Desktop (Transform Data). You also need a column that contains date-like text, and you should know the order of day, month, and year in that text so you can supply the right format string.
What You'll Need
- Excel 2016 or later, or Power BI Desktop, with Power Query accessible.
- A data source loaded into Power Query that includes a text column containing dates (for example, "2024-03-15" or "15/03/2024").
- Knowledge of the date format used in your source—whether it is day-first, month-first, or year-first.
- Optional: the locale code (such as "en-US" or "en-GB") if your data uses a regional format different from your system default.
Step-by-Step
- Load your data into Power Query. In Excel, select your table and go to Data > From Table/Range. In Power BI, use Get Data and then Transform Data. The Power Query Editor opens.
- Locate the column with text dates. Check the column header icon—it should show a text (ABC) icon. If the column already shows a date icon, you may not need this function; skip to step 8.
- Add a custom column (recommended) or transform the existing one. To keep the original text for reference, go to Add Column > Custom Column. To replace the text in place, right-click the column header and choose Transform > Custom (or use the formula bar directly). The Custom Column dialog opens.
- Enter the formula. In the formula box, type
Date.FromText([YourColumnName]). ReplaceYourColumnNamewith the actual name of your column, including square brackets. For example:Date.FromText([OrderDate]). If your text uses a non-default format, add a format string as the second argument:Date.FromText([OrderDate], "dd/MM/yyyy"). The format string uses the same placeholders as .NET:dfor day,Mfor month,yfor year. You can also add a third argument for a locale, such as"en-GB". - Click OK. Power Query adds the new column (or transforms the existing one). Each row now shows a date value. If any row fails to convert, it will show
Error. - Check the data type. Click the icon in the new column header and confirm it is set to Date. If it shows Any or Text, change it to Date.
- Handle errors. If you see errors, click the error cell to see the message. Common causes are mismatched format strings or unexpected characters. You can right-click the column and use Replace Errors to substitute a default date, or filter out error rows.
- Load the result. Go to Home > Close & Load (Excel) or Close & Apply (Power BI) to bring the cleaned data back into your workbook or model.
Common Mistakes
- Wrong format string. Using "MM/dd/yyyy" when the text is actually "dd/MM/yyyy" will swap day and month, producing incorrect dates or errors. Always match the format to the source.
- Forgetting the locale. If your system locale is en-US but the text uses en-GB conventions (day first), the default conversion may misinterpret the date. Supply the locale argument explicitly.
- Ignoring errors. A column with some error values will break downstream calculations. Always inspect and handle errors before loading.
- Using the wrong column reference. In the Custom Column dialog, column names must be in square brackets and match exactly, including spaces. For example,
[Order Date]not[OrderDate]if the header has a space. - Assuming all text is convertible. Values like "N/A" or empty strings will produce errors. Clean or filter them first.
Tips
- Use the
Date.FromTextfunction inside a custom column rather than the automatic type detection, which can guess wrong on ambiguous formats. - To test a format string quickly, create a small custom column with a literal text value, such as
Date.FromText("15/03/2024", "dd/MM/yyyy"), and see the result. - If your text includes time information, use
DateTime.FromTextinstead, then extract the date part if needed. - For columns with mixed formats, consider splitting the column or using
try ... otherwiseto handle exceptions:try Date.FromText([Column]) otherwise null. - Keep a copy of the original text column until you have verified the conversion, so you can compare and correct.
Troubleshooting
If Date.FromText returns an error for every row, check that the column reference is correct and that the text does not contain leading or trailing spaces. Use Text.Trim to clean it. If only some rows error, inspect those values—they may have a different format or contain non-date characters. If the function returns a date but the day and month are swapped, your format string is likely reversed; adjust it and refresh. If the column shows a date icon but the values are wrong, the automatic conversion may have used the wrong locale; redo the step with an explicit format and locale. When errors persist, use the Power Query error message (click the cell) to see the exact problem. If you cannot resolve it, load the data without conversion and clean the text in a later step.
Frequently Asked Questions
What is the difference between Date.FromText and Date.From?
Date.From is a more general function that can convert numbers, text, and other types to a date. Date.FromText is specifically for text and allows you to specify a format string and locale, giving you more control over parsing.
Can I convert a column with mixed date formats?
Not directly with a single format string. You would need to standardize the text first (for example, using conditional logic or splitting the column) or use try ... otherwise with multiple attempts.
Why does my date show as an error after using Date.FromText?
The most common reasons are a mismatched format string, a locale difference, or extra characters (such as spaces or non-breaking spaces) in the text. Check the exact text value and adjust the format or clean the text.
Does Date.FromText work with dates that include time?
No, it expects a date-only string. If your text includes time, use DateTime.FromText and then extract the date with DateTime.Date.
Can I use Date.FromText in Power BI measures?
No, Power Query functions like Date.FromText are for data transformation in the Power Query Editor, not for DAX measures. In DAX, use DATEVALUE or CONVERT.
What locale codes can I use?
Use standard locale codes such as "en-US", "en-GB", "fr-FR", "de-DE". The function accepts any valid culture name. If omitted, it uses the locale of the Power Query session.