I am having trouble with converting a date in PowerBI like:
Column name date:
2022-06-25 05:23:15 PDT
First off, after importing this file into my PowerBI project, the column above
is marked as text. If I try to change this column type to Date/Time/Timezone in the query editor the result in an error:
= Table.AddColumn(#"Promoted Headers", "NewDate", each DateTimeZone.FromText([date]))
DataFormat.Error: We couldn't parse the input provided as a DateTimeZone value.
Details:
2022-06-25 05:23:15 PDT
Is the use of a Timezone name a bad thing in PowerBI? All examples I search for use a UTC offset but the date I have is so common, it seems ridiculous to have to change the data to a UTC offset.
You have to do a conversion I'm afraid. Something like the following I think for PDT.
= Table.AddColumn(Source, "Custom", each DateTime.AddZone( DateTime.FromText([Column1], [Format = "yyyy-MM-dd hh:mm:ss"]), -7))
Related
I am having an issue while changing the data type of a column to Date datatype.
Issue is some dates are not in the proper date format as shown in the attached image.
Steps I have appied
Changed Type with Locale en-US
Changed Type with Locale en-GB
Changed type to Date
Need suggestions to fix this issue
Thanks in advance
Assuming your dates with locale en-GB are always with days greater than 12, you can use this function.
(_date as text) =>
let
Step1 = List.Transform(Text.SplitAny(_date,"/"), each Number.FromText(_)),
Step2 =
if Step1{0} > 12
then Date.FromText(_date,"en-gb")
else
Date.FromText(_date,"en-us")
in Step2
Otherwise, the are some dates that would have ambiguity, such as the 1st of Feb.
Issue resolved by selecting French (France) Locale settings.
I'm currently exporting data from Dynamics. There are a lot of date fields I need to export. By default they are all UTC timezone. I want to report on New Zealand timezone. I tried to approaches in Power Query:
1) use DateTimeZone.ToLocal: =Table.TransformColumns(#"dataset", {{"**UTC Date**", **DateTimeZone.ToLocal**, type datetimezone}})
2) use a specific timezone ("en-NZ"): =Table.TransformColumnTypes(#"dataset", {{"UTC Date", type datetime}}, **"en-NZ"**)
Both approaches work OK in Power BI desktop report, However once I published to Power BI service and after several refreshes (initially it was NZ time), the time turn back to UTC time.
I don't want to create extra columns in DAX and really want to try use Power Query. Is there any way to work it out?
I have faced the same issue a while back and came up with the following solution.
You can simply use a combination of RemoveZone and Addzone power query function to achieve this. Example below shows how to get Indian Standard Time(IST = +5:30)
= DateTime.AddZone(DateTimeZone.RemoveZone(DateTimeZone.UtcNow()),5,30)
Note that I used DateTimeZone.UtcNow() to always get the Universal standard DateTime and then convert this to the Indian time. You can use your own timezone values
Add the above code in place of DateTimeZone.ToLocal in your code.
Documentation to DateTime.AddZone
Power BI:
Use this Power Query function to convert times from UTC to Local Time, here its mountain time, but you can set to Whatever New Zealand Time is
let
ConvertDateColumnstoMountainTime = (sourcetable as table) as table =>
let
TargetColumnList = Table.ColumnsOfType(sourcetable, {type datetime, type nullable datetime, type datetimezone, type nullable datetimezone}),
AdjustTimeZones = Table.TransformColumns(sourcetable, List.Transform(TargetColumnList,
(name) => {name, (date) => if date <> null
then DateTime.From(DateTimeZone.RemoveZone(date) + #duration(0,CalculateUTCOffset(date,null),0,0))
else null})),
//Above returns type as text. Need it explicitly as Date.
AdjustColumnTypes = Table.TransformColumnTypes(AdjustTimeZones,List.Transform(TargetColumnList,
(name) => {name, type datetime}))
in AdjustColumnTypes
in ConvertDateColumnstoMountainTime
I have a date string that fails to import because it is in a different format to that expected my the machines locale (i.e. US dates to a UK machine).
How do I tell DAX to convert this string into a date, but using a specified format or locale, different to the machines default.
For example, I would like to import
3/27/2008 11:07:31 AM
as
27/3/2008 11:07:31 AM
You have two options.
First option, use the basic Formatting tab functionality in Power BI.
Select the column and use the below settings in the Formatting tab:
Second option (recommended), use PowerQuery to import the text column in datetime data type.
The following expression will split the text by "/" character, then will convert dd/mm/yyyy string to the datetime data type.
Table.AddColumn(#"Changed Type", "DateTime",
each Text.Split([#"#(001A)Date Import"],"/"){1} & "/"
& Text.Split([#"#(001A)Date Import"],"/"){0} & "/" &
Text.Split([#"# (001A)Date Import"],"/"){2})
In this case I've added an additional column in order to import the column in the required datetime type, you can apply the changes to the same column though.
Date import column is the actual text column, DateTime is the column I've added to import Date Importas Datetime type.
If you get stuck check the official documentation about PowerQuery.
Let me know if this helps.
I think the most practical solution is in the Query Editor, but complex formula are not required.
I would Right-click the column and choose Change Type / Using Locale. Then I would specify Data Type = Date and Locale = English (United States).
I am exporting data from Dynamics CRM 2011 into an Excel File. The entries have timestamps. In CRM they look like normal dates, but when I export them into Excel the timestamps look similar to this:
41855.4043865741
41831.6309259259
In Excel I can right-click on the cell with the timestamp and do Cell Formatting > Numbers > Date and convert this to a human readable string.
e.g.
04.08.2014 09:42:19
11.07.2014 15:08:32
The problem is, after I save the Excel with the human readable Datetime format and read the Excel with the xlrd Module (Python 2.7) I still get the strange format and not the translated one.
So I tried using datetime Module to dranslate the date but when doing so I get the wrong date.
import datetime
str_dt = float(41831.6309259259)
print datetime.datetime.fromtimestamp(str_dt).strftime('%Y-%m-%d %H:%M:%S')
My result is: 1970-01-01 12:37:11
Of course it is not Unixtimestamp but I have no idea what timestamp it actually is and how I can convert it with python.
The values you see are the actual number of days since the 1st of January 1900. This is the format used by CRM and Excel.
As suggested in this answer, you can use xlrd.xldate.xldate_as_datetime to:
Convert an Excel date/time number into a datetime.datetime object.
#param xldate The Excel number
#param datemode 0: 1900-based, 1:
1904-based.
#return a datetime.datetime() object.
In your case the datemode would be 0.
The database (SQLite) has a field of type REAL with the values of the form (42153.659595).
How to translate this value in the form "dd.MM.yy HH:mm:ss" if 42153.659595 = 29.05.2015 15:49:49 ?
You can be explicit about what calendar system you require: http://www.sqlite.org/lang_datefunc.html
SELECT julianday('now') - julianday('1776-07-04');
In principle just don't "parse" (you mean: interpret raw representation). Use Sqlite API/builtin SQL functions to do it for you
In the interest of information:
The date and time functions use a subset of IS0-8601 date and time formats.
The datetime() function returns "YYYY-MM-DD HH:MM:SS". The julianday() function returns the Julian day - the number of days since noon in Greenwich on November 24, 4714 B.C. (Proleptic Gregorian calendar)
The date() function returns the date in this format: YYYY-MM-DD. The time() function returns the time as HH:MM:SS.
The correct value is achieved using the API/builtin SQL functions (42153.659595 - value from database):
SELECT datetime(julianday(42153.659595, 'localtime') + 2415018.29167) AS DT;
Output:
DT |
2015-05-29 15:49:49|
Constant 2415018.29167 was selected manually and query:
SELECT datetime (2415018.29167);
returns the current Greenwich Mean Time.
I work with a third-party application and documentation on the database is missing. Perhaps this strange decision, but it works. Thank you all for answers.