Decision Tree Excel Add-In

Posted in: admin03/10/17Coments are closed

Solving DAX Time Zone Issue in Power BIPower BI is a cloud service, and that means Power BI files are hosted somewhere. Some DAX functions such as DateTime functions work on system datetime on the server their file is hosted on. So If you use DAX functions such as TODAY or NOW you will not get your local datetime, You will fetch servers datetime. In this blog post Ill explain methods of solving this issue, so you could use Power BI to resolve your specific time zones date and time. If you want to learn more about Power BI read Power BI online book Power BI from Rookie to Rock Star. Defining the Problem. Using DAX functions on your local Power BI file is totally different from what you will see in Power BI website especially when date and time functions has been used. The reason is that DAX works with the date and time of the system that hosted the Power BI file. Video on the steps to download and install the free decision modeling addin TreePlan for Excel. Note depending upon your PC, you may need to add the. Power BI is a could based service, and that means Power BI files will be hosted on a server somewhere in the world, that might not be on the same time zone as your city is. So as a result when you used functions that works with the current date and time such as TODAY or NOW in DAX you will not get your local current date and time. At this stage there is time zone feature in DAX functions to help resolving this, so I suggest few options to resolve it as below. Screenshot below shows a Power BI report published on Power BI website, and the result of DAX NOW function there compared with the local datetime on the client system. Please note that you wont see this anomaly in Power BI Desktop, because in that case file is running on your local system, and the result would be your local datetime, you will only face this issue when you publish solution to Power BI website. Method 1 DAX Formula Manipulation. One easy way of solving this is to add time offset to the datetime function in DAX. Power BI datetime seems to be GMT. So if I want to show my local time in Auckland, I have to add 1. Or for Seattle I have to reduce 7 hours from it. So I create a new calculation as DAX NZ TIME with this code. DAX NZ TIME NOWlt strong lt span stylecolor ff. DAX NZ TIMENOWlt strong lt span stylecolor ff. DAX Seattle Time with this code. DAX Seattle TIME NOWlt strong lt span stylecolor ff. DAX Seattle TIMENOWlt strong lt span stylecolor ff. Here is corrected result as below This method works but has an issue which I deal with it later on. Method 2 Power Query Date. Time. Zone Functions. Thanks to my friend Ken Puls who mentioned this method to me in PASS BA conference, I come with this second option. Fortunately in Power Query there is set of functions for Date. Neo Geo Roms Metal Slug 6 Game. Time. Zone. Ken already has a blog post about time zones with Power Query which is a good read and recommended. Date. Time. Zone functions has options such as fetching local time or switching time zones. For this purpose I can use Date. Time. Zone. Switch. Zone function to switch servers local time to my time zones date and time. Need For Speed Most Wanted Black Edition Setup. Date. Time. Zone. Switch. ZoneDate. Time. Zone. Local. Now,1. 2,01Date. Time. Zone. Switch. ZoneDate. Time. Zone. Local. Now,1. 2,01. NZ time. Seattle time I have to set parameters to 7, and 0. And here is the result set You can also use other functions such as Date. Time. Add. Zone in Power Query to turn the local date time to specific time zone. Well above solution works like DAX method, but both suffer from similar issue Day Light Saving Time. This is the reason that if you try code above in summer or winter you might get different result Method 3 Web Query with Power Query. Day Light Saving is a big challenge, because each time zone, city, or country might have different day light saving time. DST Daylight Saving Time for different years Power Query is intelligence enough to help with Time Zone issue, but doesnt have a directory of all DST times for all time zones. Fortunately Power Query can query web URL. And there are some websites that give you the current date and time for your specific city, country, or time zone. And those websites usually consider DST correctly. One of these websites is Time. And. Date. com. As you see in screenshot below this website gives me the current date and time for most of cities around the world In Power Query we can use functions such as Web. Page and Web. Contents to read tables in a web page, and then fetch part of it that we want with some other transformations. I wont be explaining details of using timeanddate. URL to fetch the local city here because it would make this post very long. I just refer you to my other post about reading some datetime information for different time zones which is similar to method Ive used here. If you want to understand how code below works read the post here. For this part I will be using another website which gives me current date and time in Auckland, and here is Power Query code. Source Web. PageWeb. Contentshttp localtimes. OceaniaNewZealandAuckland. Data. 1 Source1Data. Changed Type Table. Transform. Column. TypesData. 1,Column. Column. 2, type text. Changed Type1Column. Changed Type0Column. Date. Time. From. Textdate time. SourceWeb. PageWeb. Contentshttp localtimes. OceaniaNewZealandAuckland,    Data. Source1Data,    Changed Type Table. Transform. Column. TypesData. 1,Column. Column. 2, type text,    dateChanged Type1Column. Changed Type0Column. Date. Time. From. Textdate timein    datetime. And here is the result with the correct DST and time zone Method 3 Revisited with Xml. Documentthe method mentioned with web query uses Web. Page Power Query function and hence it requires gateway setup to work. Thanks to Yingwei Yang from Microsoft team who suggested this approach there is another way which doesnt require gateway setup using Xml. Document function. Lets go through that solution. Timezonedb. com is the website that has an api to return timezone information, fortunately api is free to use. API Key which you can use in a api url as below To learn more about API read this link. Now that we have an api to work with, we can use Xml. Document function to read data from it. Enermax Meter Software on this page. Blank Query in Power Query, then go to View Advanced Editor and replace the whole query with below script. Source Xml. DocumentWeb. Contentshttp api. XYZ formatxml byzone zonePDT. Value Source0Value. Value. 1 Value1. Value. Value. 1let     SourceXml. DocumentWeb. Contentshttp api. XYZ formatxml byzone zonePDT,    ValueSource0Value,    Value. Value1. 2Valuein    Value. This method is the recommended method from all above options. Other Methods. At the time of writing this post, Ive only thought about these three methods. You might have an idea about another method. In that case, dont hesitate to share it here. Reza Rad is an Author, Trainer, Speaker and DWBI Consultant. He has a BSc in Computer engineering he has more than 1. Microsoft technologies. He is a Microsoft MVP in Data Platform for seven continues years from 2. Microsoft BI. He is author of some SQL Server and BI books, and also Power BI online book from Rookie to Rock Star.