Power Query - Returning DateTime type rather than Date

Comfy
Posts: 4
Joined: Wed May 03, 2017 1:06 am

Power Query - Returning DateTime type rather than Date

Postby Comfy » Fri Aug 31, 2018 9:57 pm

X-Post: https://www.mrexcel.com/forum/power-bi/ ... -date.html

I'm struggling to convert a certain column to Date rather than Datetime.

Any ideas?

Comfy
Posts: 4
Joined: Wed May 03, 2017 1:06 am

Re: Power Query - Returning DateTime type rather than Date

Postby Comfy » Fri Aug 31, 2018 10:43 pm

I've had to update the AddNColumns function to the following to fix it:

Code: Select all

let


    Source = (TableToAddTo as table, ColumnsToAdd as table, optional RowNumber as number) =>
   
    let
        ActualRowNumber = if (RowNumber=null) then 0 else RowNumber,
        AddColumn = if Text.Lower(ColumnsToAdd{ActualRowNumber}[Format]) = "date"
                    then   
                        Table.AddColumn(TableToAddTo, ColumnsToAdd{ActualRowNumber}[Journal Column Name], each DateTime.Date(ColumnsToAdd{ActualRowNumber}[Column Value]), GetType(Text.Lower(ColumnsToAdd{ActualRowNumber}[Format])))
                    else
                        Table.AddColumn(TableToAddTo, ColumnsToAdd{ActualRowNumber}[Journal Column Name], each ColumnsToAdd{ActualRowNumber}[Column Value], GetType(Text.Lower(ColumnsToAdd{ActualRowNumber}[Format]))),
        NextRowNumber = ActualRowNumber + 1,
        OutputTable = if NextRowNumber > (Table.RowCount(ColumnsToAdd) - 1)
                    then
                        AddColumn
                    else
                        AddNColumns(AddColumn, ColumnsToAdd, NextRowNumber)
    in
        OutputTable
in
    Source


Return to “Power Query”

Who is online

Users browsing this forum: No registered users and 1 guest

cron