- March 25, 2016
- Posted by: Scaleable Solutions
- Category: Power BI
Most of the times while importing date data from different sources the format is in UTC time format. For the accurate reporting and visuals in Power BI dashboards we need to have this in local time format. In this post we will see how you can convert the UTC date data into local time format.
For example if we have the following Opportunity data from Dynamics CRM, there is a column called EstimatedCloseDate which is in the UTC format. We want to convert this date into our local time zone format.
First of all lets rename this column to EstimatedCloseDateUTC. Then go to the “Transform” tab in the ribbon and change its datatype to Date/Time/TimeZone. Next we can use the Add Column transformation to insert new column in the Query. To do this, we can go to the Add Column tab in the ribbon and click on the Date->DateOnly menu item. This will add a second column with the date as shown below.
When you add this transformation the following M code was generated for this step.
= Table.AddColumn(#”Changed Type”, “Date”, each DateTime.Date([EstimatedCloseDateUTC]), type date)
In this M code we need to manually replace the DateTime.Date function with the DateTimeZone.ToLocal function. Next the data type of this new column can set to Date Only. When this is done we get the following result
To finish we can remove the EstimatedCloseDateUTC column and rename Date to EstimatedCloseDate.
And thats it , you have successfully transformed a UTC time format date to your local time zone format.