Forum Discussion
AndrewDang
9 years agoHelper IV
Set local time zone Power BI Service
Hello all; I have an issue with setting the right local time for my Power BI Service. I have the same measure to pull the current time. My Power BI desktop file pulls up 1/16/2017 4:36:02 PM whic...
slittle4782
2 years agoAdvocate I
I had a somewhat similar issue...
I had a column of datetimes in the PowerBI service which are in UTC. I needed to be able to group the records by date... but based on the date Pacific Time (UTC-7 or UTC-8 depending on daylight saving time).
Was able to use the following code to create the new column...
let
// This converts the time to PacificTime
//CurrentYear = Date.Year(DateTime.LocalNow()),
//DaylightTimeStart = Date.StartOfWeek (#date(CurrentYear,3,14),Day.Sunday),
//StandardTimeStart = Date.StartOfWeek (#date(CurrentYear,11,7),Day.Sunday),
Source = Sql.Database("hercules3", "BC"),
#"Navigation 1" = Source{[Schema = "dbo", Item = "Technical Prospects LLC$Shipping Checklist"]}[Data],
#"Choose columns" = Table.SelectColumns(#"Navigation 1", {"Created At", "Cleaned By", "Packaged By", "Pre-Pack", "Entry No_"}),
#"Filtered rows" = Table.SelectRows(#"Choose columns", each [Created At] >= EarliestTimeDateforData),
#"Changed column type" = Table.TransformColumnTypes(#"Filtered rows", {{"Created At", type datetimezone}}),
// The "Created at" field is datetimezone in UTC. We need to add a column to return the date (in Pacific Time) so that we can group all records based on this date
#"+Created at Date (Pacific Time)" = Table.TransformColumnTypes(Table.AddColumn(#"Changed column type", "Created at Date (Pacific Time)", each let
// Get the year of the UTC datetime
year = Date.Year(DateTimeZone.RemoveZone([Created At])),
// Calculate the start and end of DST for the given year (second Sunday in March and first Sunday in November - this works for the U.S.)
dstStart = DateTimeZone.SwitchZone(
DateTimeZone.From(
Date.AddDays(#date(year, 3, 8),
7 - Date.DayOfWeek(#date(year, 3, 8), Day.Sunday))
), -8, 0
),
dstEnd = DateTimeZone.SwitchZone(
DateTimeZone.From(
Date.AddDays(#date(year, 11, 1),
7 - Date.DayOfWeek(#date(year, 11, 1), Day.Sunday))
), -7, 0
),
// Determine if the datetime falls within DST or not
pacificDateTime = if DateTimeZone.From([Created At]) >= dstStart and DateTimeZone.From([Created At]) < dstEnd
then DateTimeZone.SwitchZone(DateTimeZone.From([Created At]), -7, 0) // PDT is UTC-7
else DateTimeZone.SwitchZone(DateTimeZone.From([Created At]), -8, 0) // PST is UTC-8
in
pacificDateTime), {{"Created at Date (Pacific Time)", type date}}),
#"Removed columns" = Table.RemoveColumns(#"+Created at Date (Pacific Time)", {"Created At"})
in
#"Removed columns"