Forum Discussion
DateTimeZone not recognized when using DateTimeZone.SwitchZone(DateTime.LocalNow(),3,0)
- 6 years ago
Hi sandra_p ,
You may select on the new created datetime column, go to Transform tab, choose Data Type and select Date/Time/TimeZone instead of Date/Time, don't forget to click button "Close & Apply".
For reference:
https://community.powerbi.com/t5/Desktop/Convert-UTC-to-client-time-zones/td-p/56337
https://community.powerbi.com/t5/Desktop/Convert-UTC-to-local-time-zone-in-DAX/td-p/43328
https://radacad.com/solving-dax-time-zone-issue-in-power-bi
Best Regards,
Amy
Community Support Team _ Amy
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi Sandra,
Your best shot is to take the UTC time, and convert it to your desired daylight savings time as described here: https://gorilla.bi/power-query/last-refresh-datetime/
That works with this logic:
let
UTC_DateTimeZone = DateTimeZone.UtcNow(),
UTC_Date = Date.From(UTC_DateTimeZone),
StartSummerTime = Date.StartOfWeek(#date(Date.Year(UTC_Date), 3, 31), Day.Sunday),
StartWinterTime = Date.StartOfWeek(#date(Date.Year(UTC_Date), 10, 31), Day.Sunday),
UTC_Offset = if UTC_Date >= StartSummerTime and UTC_Date < StartWinterTime then 2 else 1,
CET_Timezone = DateTimeZone.SwitchZone(UTC_DateTimeZone, UTC_Offset)
in
CET_Timezone
The important aspects here are:
Returning a fixed UTC datetimezone value, regardless of the refresh location of the server. Details here:
https://powerquery.how/datetimezone-utcnow/
And then switching the datetimezone value to the right zone as described here:
https://powerquery.how/datetimezone-switchzone/
Hope that helps - Rick
--------------------------------------------------
@ me in replies or I'll lose your thread
Master Power Query M? -> https://powerquery.how
Read in-depth articles? -> BI Gorilla
Youtube Channel: BI Gorilla
If this post helps, then please consider accepting it as the solution to help other members find it more quickly.