In my previous blog I demonstrated how to transform DateTime columns, from the Microsoft Dynamics CRM Online Organisation ODataSets loaded into Microsoft Excel, into Date columns and Year columns. There is however a step to be completed prior to that if you want the DateTime values to be converted from UTC Date/Time to Local Date/Time values.
Using the example of the CreatedOn column from the Opportunity ODataSet, the steps to perform this conversion are:
1. Select Add Custom Column from the Add Column tab on the Query Editor ribbon bar..png?sfvrsn=2)
.png?sfvrsn=2)
.png?sfvrsn=2)
The formula works by:
• Adding the UTC Zone to the UTC Date/Time; e.g. using DateTime.AddZone([CreatedOn], 0) converts 5/11/2014 8:01:54 p.m. to 5/11/2014 8:01:54 p.m. +00.• Converts the UTC Date/Time/Zone to Local Date/Time/Zone; e.g. DateTimeZone.ToLocal( … ) converts 5/11/2014 8:01:54 p.m. +00 to 6/11/2014 9:01:54 p.m. +13.• Removes the Zone from the Local Date/Time/Zone; e.g. using DateTimeZone.RemoveZone( … ) converts 6/11/2014 9:01:54 p.m. +13 to 6/11/2014 9:01:54 p.m.The following image shows the result:
You can convert the CreatedOnLocal column to a Date in the same step by modifying the custom formula to: DateTime.Date(DateTimeZone.RemoveZone(DateTimeZone.ToLocal(DateTime.AddZone([CreatedOn],0))))
The following formulas may be used, in conjunction with Add Custom Column, to add CreatedOn, EstimatedCloseDate and ActualCloseDate Date and Year columns, based on Local Date/Time rather than UTC Date/Time, to the ODataSet:
• DateTime.Date(DateTimeZone.RemoveZone(DateTimeZone.ToLocal(DateTime.AddZone([CreatedOn],0))))• Date.Year(DateTimeZone.RemoveZone(DateTimeZone.ToLocal(DateTime.AddZone([CreatedOn],0))))• DateTime.Date(DateTimeZone.RemoveZone(DateTimeZone.ToLocal(DateTime.AddZone([EstimatedCloseDate],0))))• Date.Year(DateTimeZone.RemoveZone(DateTimeZone.ToLocal(DateTime.AddZone([EstimatedCloseDate],0))))• DateTime.Date(DateTimeZone.RemoveZone(DateTimeZone.ToLocal(DateTime.AddZone([ActualCloseDate],0))))• Date.Year(DateTimeZone.RemoveZone(DateTimeZone.ToLocal(DateTime.AddZone([ActualCloseDate],0))))Notice that DateTime.Date() is used to convert to Date and Date.Year() is used to convert to Year.
This approach achieves the same results as demonstrated in my previous blog, but with the advantage that the Date/Time values are also converted to Local Date/Time prior to being converted to Date and Year.
In my next blog I will demonstrate how to reorder and rename the columns. In subsequent blogs I will then demonstrate how to build some simple PowerPivot, Power View and Power Map reports in Microsoft Excel using the ODataSets loaded from the Microsoft Dynamics CRM Online Organisation.