As mentioned in these threads: - http://community.powerbi.com/t5/Integrations-with-Files-and/Date-issues-with-Sharepoint-file-sources/m-p/372661#M16100 - https://community.powerbi.com/t5/Desktop/Sh...
Anonymous
5 years agoNot applicable
I have created the following function to solve the issue for myself.
It should be invoked as fixSharepointFiles(Sharepoint.Files(Site-URL, [ApiVersion = 15]))
It uses the try keyword to get to the source string and then handles the original string under the assumption that it is in the en-US locale.
If the automatic conversion did not error out, it's because Power Query assumed that the day was the month and vice versa, so I switch them back.
It seems to work without a problem for me but you may need to correct for the timezone of the Sharepoint server.
let fixSharepointFiles = (Sourcetable as table ) as table =>
let
fixSharepointDates = (cellRecord as record) as nullable datetime =>
let
result = //Error => use US locale
if cellRecord[HasError] then DateTime.FromText(cellRecord[Error][Detail], "en-US")
//null stays null
else if cellRecord[Value] = null then null
//if a valid DateTime was recognized, PQ switched month and day, so we switch it back
else
//store current value in Record
let datetimeRecord = DateTime.ToRecord(cellRecord[Value]),
//create new datetime with correct order
fixedDate = #datetime(datetimeRecord[Year],datetimeRecord[Day],datetimeRecord[Month],datetimeRecord[Hour], datetimeRecord[Minute], datetimeRecord[Second])
in fixedDate
in
result,
#"Add DateRecords" = Table.AddColumn(Sourcetable, "DateRecords", each [#"Date accessed" = (try [Date accessed]), #"Date modified" = (try [Date modified]), #"Date created" = (try [Date created])]),
#"Remove old date columns" = Table.RemoveColumns(#"Add DateRecords",{"Date accessed", "Date modified", "Date created"}),
#"Expand DateRecords" = Table.ExpandRecordColumn(#"Remove old date columns", "DateRecords", {"Date accessed", "Date modified", "Date created"}, {"Date accessed", "Date modified", "Date created"}),
#"Process and transform date records" = Table.TransformColumns(#"Expand DateRecords", {{"Date accessed", fixSharepointDates},{"Date modified", fixSharepointDates},{"Date created", fixSharepointDates}})
in
#"Process and transform date records"
in
fixSharepointFiles