Power Query DateTimeZone.FromFileTime: How to Use It
In this article
DateTimeZone.FromFileTime converts a Windows file time value (a 64-bit integer counting 100-nanosecond intervals since 1 January 1601 UTC) into a proper datetimezone value in Power Query. You call it in a custom column or a query step, and Power Query returns the UTC date and time with a zero offset, which you can then convert to local time with DateTimeZone.ToLocal or another conversion. Nothing needs to be installed first; the function is built into Power Query in Excel, Power BI Desktop and Power BI Service dataflows, so you only need a query that already contains the numeric file time column.
What You'll Need
- Power Query Editor open in Excel (Data > Get Data > Launch Power Query Editor), Power BI Desktop (Transform data), or a Power BI dataflow. Menu labels can differ slightly by version, edition and region.
- A source column that holds the file time as a whole number (Int64). Typical sources are Windows event logs, registry exports, Active Directory attributes such as lastLogonTimestamp, or any system that stores timestamps in FILETIME format.
- The column must be typed as Whole Number or Int64, not as Text or Decimal. A text value will fail with an expression error.
Step-by-Step
- Load or connect to your data so the query appears in the Queries pane on the left of the Power Query Editor.
- Select the query, then check the file time column's data type in the column header. If it shows ABC or 1.2, click the type icon and choose Whole Number. For very large values that overflow, use Int64.
- Go to Add Column > Custom Column. (If you prefer to replace the existing column, use Transform > Custom Column instead; the formula is the same.)
- Name the new column, for example EventTimeUTC.
- In the formula box, enter the function with your column name in brackets, for example:
DateTimeZone.FromFileTime([FileTime]) - Click OK. Power Query adds the step and shows the converted values. They will appear as date, time and a +00:00 offset because file times are UTC by definition.
- If you want local time instead of UTC, add another custom column with
DateTimeZone.ToLocal(DateTimeZone.FromFileTime([FileTime])), or useDateTimeZone.SwitchZonewith a fixed offset when the data must always show a specific zone regardless of the machine running the refresh. - Set the new column's type explicitly to Date/Time/Zone using the type icon, so later steps and the data model treat it correctly.
- Remove the original numeric column if it is no longer needed (right-click the column header > Remove), then click Close & Load or Close & Apply.
Common Mistakes
- Leaving the source column as text. A quoted number such as "132456789012345678" produces an expression error. Convert it to Whole Number or Int64 first, or wrap it in Number.FromText.
- Using DateTime.FromFileTime instead. That returns a datetime with no zone information, so the UTC nature of the value is lost. Use the DateTimeZone version when the time zone matters.
- Assuming the result is local time. It is not. File times are UTC, and the function returns +00:00. If your report shows times four or five hours off, you skipped the local conversion.
- Using DateTimeZone.ToLocal in a scheduled cloud refresh. In the Power BI Service, ToLocal uses the service's time zone, not yours, so results can shift. Use SwitchZone with an explicit offset for predictable output.
- Passing a decimal. Fractional values cause errors. Round or truncate to a whole number first with Number.Round or Number.IntegerDivide.
- Forgetting the column reference brackets. Writing
DateTimeZone.FromFileTime(FileTime)without square brackets is read as an unknown identifier.
Tips
- Test the formula on a single known value first. For example, a file time of 132537600000000000 corresponds to 1 January 2021 00:00:00 UTC, which is an easy sanity check.
- Keep the original numeric column until you have verified the conversion; it is the only way to trace a wrong result back to the source.
- If your source stores Unix epoch seconds rather than Windows file times, use
DateTimeZone.From([Seconds] / 86400 + #datetimezone(1970,1,1,0,0,0,0,0))instead; the file time function is not the right tool there. - For daylight saving accuracy in a fixed region, use DateTimeZone.SwitchZone with the correct standard or daylight offset for the date in question, since Power Query does not carry a full time zone database in this function.
- Document the conversion step with a comment or a clear step name so the next person editing the query understands why the column exists.
Troubleshooting
Expression.Error: We cannot convert the value to type Number. The column is text or contains blanks. Filter out nulls, then change the type to Whole Number.
Expression.Error: The value is too large. The number exceeds the Decimal range. Change the type to Int64 rather than Whole Number.
All results show the same date. The column reference is probably pointing at the wrong column, or a step above changed the type to Date and truncated the time. Check the Applied Steps list in order.
Times are off by a fixed number of hours. You are seeing UTC where you expected local time, or the reverse. Add or remove the ToLocal or SwitchZone step and compare one known record.
The column shows an error only on some rows. Those rows likely contain null, empty text or a decimal. Use try DateTimeZone.FromFileTime([FileTime]) otherwise null to handle them gracefully.
Refresh fails only in the service. A local-time conversion is the usual cause. Replace ToLocal with SwitchZone using a fixed offset, then republish.
Frequently Asked Questions
What exactly does DateTimeZone.FromFileTime return?
A datetimezone value in UTC, with a +00:00 offset, built from the 100-nanosecond intervals since 1 January 1601.
Does it work in Excel Power Query as well as Power BI?
Yes. The function is part of the shared Power Query formula language, so it behaves the same in Excel, Power BI Desktop and dataflows.
Can I convert the result to a plain date?
Yes. Wrap it in DateTimeZone.ToText or use Date.From on the result if you only need the date portion.
Why is my converted time different from what Windows shows?
Windows usually displays local time, while the function returns UTC. Apply DateTimeZone.ToLocal or SwitchZone to match.
Can it handle null values?
No. A null input produces an error, so wrap the call in try...otherwise null or filter nulls before the step.
Is there a reverse function?
Yes. DateTimeZone.ToFileTime converts a datetimezone back into a file time number, which is useful for round-trip checks.