Forum Discussion
Convert UTC to client time zones?
- 10 years ago
Hi Betsy,
We may take a try with the method below:
Assuming currently we have the Time and UTC column in a table, where [Time] stores the actual UTC time, [UTC] stores the changed hour count between client and UTC.
Based on the different Time Zone, UTC values changes within -12 to 12 range.
When data loaded into Power BI, open Query Editor, under the Add column tab, click Add Custom Column, then under the formula part, copy and paste the following:
DateTime.AddZone([Time],0)Click OK. This step adds the default UTC Time Zone (0 here) under the time stored in [Time], to the newly created ZoneTime column;
After that, we need to create another column to switch the time zone to the client, also click on the Add custom column, then copy and paste the following formula:
DateTimeZone.SwitchZone([ZoneTime],[UTC])
After that, we have successfully added the time Zone information into the time. Then we need format the column into date/time/timezone format.
Select ClientTime column, navigate to Transform tab, choose data type and select Date/Time/TimeZone:
After that, click close and apply.
Till then we should have finished converting the time into Client local time.
If any further questions, please feel free to post back.Regards,
Charlie Liao
Assumption:
You have a datetime column that YOU know is in UTC ( but probably power bi does not know that)
If you have a column in UTC, tell power bi so by creating a new colum called "utc_time" based on your prior utc column, use this code: DateTime.AddZone([ here put the name of your utc column ], 0 )
Now you will notice some zeros:
Change the data type to "date time zone":
Now select the new column, go to Add Column> Time and click on "Local Time":
This is the magic column that is useful for your reports, just change the name of the column (if you like) :
Warning that Power Query running on your local computer will convert this to YOUR local time, HOWEVER - if you intend to refresh your dataset in the cloud - it will be running on the server, which uses UTC as it's local time. For me, the LocalTime feature is pretty useless. Maybe if you are just conducting the analysis one time, not trying to make a continuously updating report?