Date formats in Power Query are one of those little issues that drives me nuts… you have a query of different information in Power Query, at least one of the columns of which is a date. But when you complete the query, it doesn’t show up as a date. Why is this?
Demonstrating the Issue
Have a look at the following table from Excel, and how it loads in to Power Query:
That looks good… plainly it’s a date/time type in Power Query, correct? But now let’s try an experiment. Load this to the worksheet:
Why, when we have something that plainly renders as a date/time FROM a date format, are we getting the date serial number? Yes, I’m aware that this is the true value in the original cell, but it’s pretty misleading, I think.
It gets even better
I’m going to modify this query to load to BOTH the worksheet and the Excel data model. As soon as I do, the format of the Excel table changes:
Huh? So what’s in Power Pivot then?
Curious… they match, but Power Pivot is formatted as Text, not a date?
(I’ve missed this in the past and spent HOURS trying to figure out why my time intelligence functions in Power Pivot weren’t working. They LOOK so much like datetimes it’s hard to notice at first!)
Setting Date Formats in Power Query
When we go back and look at our Power Query, we can discover the source of the issue by looking at the Data Type on the Transform tab:
By default the date gets formatted as an “Any”. What this means to you – as an Excel user – is that you could get anything out the other end. No… that’s not quite true. It means that it will be formatted as Text if Power Pivot is involved anywhere, or a Number if it isn’t. I guess at least it’s consistent… sort of.
Fixing this issue is simple, it’s just annoying that we have to. In order to take care of it we simply select the column in Power Query, then change the data type to Date.
Unfortunately it’s not good enough to just say that you’ve set it somewhere in the query. I have seen scenarios where – even though a column was declared as a date – a later step gets it set back to Any.
I’ve been irritated by this enough that I now advise people to make it a habit to set the data types for all of their columns in the very last step of the query. This ensures that you always know EXACTLY what is coming out after all of your hard work and eliminates any surprises.