Power Query DateTime.From Function: Step-by-Step
In this article
The DateTime.From function in Power Query converts a value into a datetime (date and time combined) value. It's used in Power Query Editor (available in Excel and Power BI) to standardize data that comes in as text, numbers, or other formats. The function takes a single argument—the value you want to convert—and returns a datetime in the format yyyy-mm-dd hh:mm:ss. If the value is already a datetime, it returns it unchanged. If it's a date, it adds midnight (00:00:00). If it's a time, it uses the current date (which can be unpredictable, so be careful). You'll need access to Power Query Editor, which is built into Excel (Data > Get Data) and Power BI (Home > Transform Data).
What You'll Need
- A computer with Excel 2016 or later, or Power BI Desktop.
- A data source that contains values you want to convert to datetime (e.g., a column of text dates, or numbers representing dates).
- Basic familiarity with opening Power Query Editor (in Excel: Data > Get Data > From Table/Range; in Power BI: Home > Transform Data).
Step-by-Step
- Open Power Query Editor. In Excel, select your data range, go to the Data tab, and click From Table/Range (if your data isn't already a table, Excel will prompt you to create one). In Power BI, click Transform Data from the Home tab. The editor opens in a new window.
- Select the column that contains the values you want to convert. Click on the column header—it will highlight.
- Add a custom column. Go to the Add Column tab and click Custom Column. This opens a dialog box where you can write a formula.
- Enter the formula. In the Custom column formula box, type
DateTime.From([YourColumnName]), replacingYourColumnNamewith the actual name of your column. For example, if your column is called "DateText", typeDateTime.From([DateText]). If you're unsure of the column name, look at the list on the right—it shows available columns. - Name your new column. In the New column name field, type something descriptive like "ConvertedDateTime". Click OK. Power Query adds a new column with the converted values.
- Check the data type. The new column should show a datetime icon (a clock with a calendar). If it shows a different icon (like ABC for text), you may need to change the data type manually. Select the new column, go to the Home tab, and click the Data Type dropdown—choose Date/Time.
- Close and load. Once you're satisfied, go to the Home tab and click Close & Load (Excel) or Close & Apply (Power BI). Your converted data appears in your worksheet or report.
Common Mistakes
- Forgetting to use square brackets. The column reference must be in square brackets, like
[DateColumn], not parentheses. - Using the wrong column name. If the column name has spaces or special characters, you still write it exactly as it appears, but you might need to use
#["Column Name"]for names with spaces. For example,DateTime.From(#"Date Value"). - Assuming text dates are recognized.
DateTime.Fromworks best with text that looks like a date (e.g., "2023-01-15"). If your text is in a format like "15/01/2023" (day/month/year), Power Query might interpret it incorrectly depending on your regional settings. In that case, useDateTime.FromTextwith a format specifier instead. - Using it on a column that already contains errors. If any cell has an error (like #N/A), the entire column conversion may fail. Clean errors first.
- Not handling nulls. If a cell is blank,
DateTime.Fromreturns an error. Usetryor a conditional check to handle nulls.
Tips
- Use
DateTime.FromTextfor messy text. If your text dates are in a non-standard format,DateTime.FromTextwith a format string (like "yyyy-MM-dd HH:mm:ss") gives you more control. - Combine with
tryfor error handling. Wrap the function intryto return a default value instead of an error. For example:try DateTime.From([DateText]) otherwise null. - Convert to date or time separately. If you only need the date part, use
Date.From; if only time, useTime.From. These are simpler and less error-prone. - Check your locale. Power Query uses your system's locale to interpret ambiguous dates. If you're sharing files, consider using ISO format (yyyy-mm-dd) to avoid confusion.
- Use the Query Editor's "Detect Data Type" feature. Before writing the formula, select the column, go to the Home tab, and click Detect Data Type. Power Query may already convert it correctly without a custom column.
Troubleshooting
If the function returns an error like "Expression.Error: We cannot convert the value to DateTime": This usually means the input is not in a recognizable format. Check the original values—are they text like "January 15, 2023"? That may require DateTime.FromText with a format. Are they numbers like 44946 (Excel's serial date)? Then use DateTime.From on the number directly—it should work if the number is a valid serial. If it's a number like 20230115 (YYYYMMDD), you'll need to convert it to text first and then parse it.
If the new column shows "Error" for some rows but not others: This indicates that some values in your column are not convertible. Use the try function to catch errors, or filter out problematic rows before conversion. To see which rows fail, add a custom column with try DateTime.From([Column]) and expand the HasError field.
If the datetime looks wrong (e.g., date is off by one day): This often happens with timezone or locale issues. Power Query stores datetime in UTC by default? Actually, no—it stores in your local timezone unless you specify. If you're seeing a shift, check your Power Query options under File > Options and Settings > Query Options for timezone settings. Also, if your source data includes a timezone offset, you may need to handle it separately.
If the column doesn't appear after closing and loading: Make sure you clicked Close & Load (Excel) or Close & Apply (Power BI). In Excel, if you're loading to a table, check the worksheet—it might be on a new sheet. In Power BI, the column appears in the Fields pane.
Frequently Asked Questions
Can I use DateTime.From on a column of numbers?
Yes, if the numbers are Excel serial dates (like 44946 for 2023-01-15). The function will convert them to datetime. If the numbers are in another format (like YYYYMMDD), you'll need to convert them to text first.
What's the difference between DateTime.From and DateTime.FromText?
DateTime.From expects a value that is already in a date/time-like format (text, number, date, time). DateTime.FromText is specifically for text and lets you specify a format string to parse complex text dates.
Does DateTime.From handle null or blank values?
No, it returns an error. You need to handle nulls yourself, for example by using if [Column] = null then null else DateTime.From([Column]).
Can I use DateTime.From in a calculated column in Power BI?
Yes, you can use it in DAX calculated columns, but the syntax is slightly different—you'd use DateTime.From([Column]) in DAX as well, but DAX has its own conversion functions like DATEVALUE. In Power Query (M language), it's used as described here.
Why does my datetime show a time of 00:00:00?
That's normal when the source value is a date without time. DateTime.From adds midnight to date values. If you don't need the time part, use Date.From instead.
Does DateTime.From respect regional date formats?
It uses your system's locale for interpreting text. If you need to ensure a specific format, use DateTime.FromText with a format string like "dd/MM/yyyy HH:mm:ss" to avoid ambiguity.