Apr 19, 2023
When loading data into Power BI, it is often necessary to convert date columns to datetime columns. This is because Power BI uses datetime columns for its internal data storage for incremental load. There are a number of ways to convert date columns to datetime columns in M code. One way is to use the DateTime.From
function. The DateTime.From
function takes a date string as its input and returns a datetime value. For example, the following M code will convert the date column Date
to a datetime column:
let
DateColumn =Table.Column(MyTable, "Date"),
DateTimeColumn =DateColumn.Transform(
(d) => DateTime.From(d)
)
in
DateTimeColumn
Another way to convert date columns to datetime columns is to use the Date.ToDateTime
function. The Date.ToDateTime
function takes a date value as its input and returns a datetime value. For example, the following M code will convert the date value 2023-04-19
to a datetime value:
let
DateValue = Date.From("2023-04-19"),
DateTimeValue = DateValue.ToDateTime()
in
DateTimeValue