{"id":10280,"date":"2021-01-28T19:27:54","date_gmt":"2021-01-29T01:27:54","guid":{"rendered":"https:\/\/threecloud.wpengine.com\/post\/daylight-savings-time-changes-in-power-query\/"},"modified":"2022-11-30T09:23:53","modified_gmt":"2022-11-30T15:23:53","slug":"daylight-savings-time-changes-in-power-query","status":"publish","type":"post","link":"https:\/\/3cloudsolutions.com\/resources\/daylight-savings-time-changes-in-power-query\/","title":{"rendered":"Daylight Savings Time Changes in Power Query"},"content":{"rendered":"<p>In this post, I\u2019ll show how to accommodate for Daylight Savings Time changes in a Power BI file. The video I\u2019ve included will show the formulas that I use and how they adapted from Daylight Savings Time to Standard Time. There are many ways to do this and it is best to find a way that accommodates what you need to do, but I\u2019ll walk through how I do it for my needs within Power Query.<\/p>\n<ul>\n<li>The first thing I do in Power Query is to identify the start and end date of Daylight Savings Time. In the US, the start date is the second Sunday in March and end date was the first Sunday in November and I\u2019ve added the time of 2:00am.<\/li>\n<li>You could look these up and make a list of them for the next 8 or 10 years but to do it formulaically, I use a DateTime.LocalNow and Date.Year to pull the year out of whatever year we are in.<\/li>\n<li>In the Applied Steps area in my query settings, I create a small temporary calendar table using that the year that will start in March and end in November. I create a list of those dates under source and then I convert that list into the actual dates.<\/li>\n<li>No I have a calendar table with column1 being all dates listed from the start of March thru November. Using the Added Custom fields in Applied Steps, I add a column for month number and one for number of the day of the week (0-6).<\/li>\n<li>Since I\u2019m only interested in Sundays in March and November, I filter this table to show me only Sundays (day of week 0) in those months. More specifically, I need to know the second Sunday in March and the first Sunday in November. To do that, I want to group rows by their month number and then add an index column.<\/li>\n<li>If I click on one of the columns in my table, I can see a Sunday index which is counting in order (1<sup>st<\/sup>, 2<sup>nd<\/sup>, 3<sup>rd<\/sup> Sunday). If I remove the other columns and just keep the one with the index and expand it, I see I have all the information pieces I need (month number, Sunday index columns).<\/li>\n<li>Next, I\u2019ll add a little helper column (GetDays) that will combine the month number and Sunday index columns together. I filter that helper column for the 2<sup>nd<\/sup> Sunday in March and the 1<sup>st<\/sup> Sunday in November.<\/li>\n<li>So, I have all I need but I just need to add a time, so I\u2019ll put a time component in and combine it with the date, so I have a DateTime column.<\/li>\n<li>It\u2019s important to note that when we do comparisons in Power Query between dates, date times or date time zone, you want to be consistent with your format. If I\u2019m going to compare date time zones, I need to put my date times into a date time zone. I also need to ensure that the time zone is the same, so I\u2019m going to use a consistent switch. I\u2019ll add a time zone to my start and end dates.<\/li>\n<li>I\u2019ve added two queries (StartTime and EndTime) in which I\u2019ll reference that DateTime list. In my formulas, I\u2019ll write in the DateTime in March as the min and the end DateTime in November as the max. I\u2019ll also need to add the time zone to each and make sure I\u2019m consistent. Check out my video for more detail of the formulas.<\/li>\n<li>The logic here is an If\/Then statement. If the switch time zone which I\u2019ve set to -4 (which is Eastern Time during Daylight Savings), is greater than the start time and less than the end time, then we are in Daylight Savings and the time is correct.<\/li>\n<li>If it\u2019s not in between those two dates, then we\u2019re not in Daylight Savings and we need to subtract an hour from it because now we\u2019re going to fall back. In other words, we\u2019re going to be 5 hours behind instead of four. If I refresh it again, it should match the time that\u2019s on my computer. In my SwitchTime Zone column, I see the time that it was in the summer and in my DateTime with DST Correction column I see the correct time now which matches my computer, so I know that this is working correctly.<\/li>\n<li>But how do I know it\u2019s working to the exact second? I\u2019ll just duplicate my three queries and create a testing query. In this testing query I will arbitrarily set the start and end time to be a specific day and time to check back on my table to see if it matches. This testing helps ensure that it\u2019s working perfectly.<\/li>\n<\/ul>\n<p>My video below goes into more detail and may make this written demo clearer. I hope my peek into how I can accommodate for Daylight Savings within Power Query is helpful. This is certainly not the only way to do this, but it works well for me, so I thought it was worth sharing.<\/p>\n<p><iframe loading=\"lazy\" src=\"https:\/\/www.youtube.com\/embed\/rrHFu9mBcb8\" width=\"560\" height=\"315\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n<p>Need further help? Our expert team and solution offerings can help your business with any Azure product or service, including Managed Services offerings. Contact us at 888-8AZURE or\u00a0 <a href=\"mailto:sales@3cloudsolutions.com\">sales@3cloudsolutions.com<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this post, I\u2019ll show how to accommodate for Daylight Savings Time changes in a&mldr;<\/p>\n","protected":false},"author":31,"featured_media":10703,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"content-type":"","footnotes":""},"categories":[260],"tags":[],"class_list":["post-10280","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-data-ai","topics-blog"],"acf":[],"_links":{"self":[{"href":"https:\/\/3cloudsolutions.com\/wp-json\/wp\/v2\/posts\/10280","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/3cloudsolutions.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/3cloudsolutions.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/3cloudsolutions.com\/wp-json\/wp\/v2\/users\/31"}],"replies":[{"embeddable":true,"href":"https:\/\/3cloudsolutions.com\/wp-json\/wp\/v2\/comments?post=10280"}],"version-history":[{"count":0,"href":"https:\/\/3cloudsolutions.com\/wp-json\/wp\/v2\/posts\/10280\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/3cloudsolutions.com\/wp-json\/wp\/v2\/media\/10703"}],"wp:attachment":[{"href":"https:\/\/3cloudsolutions.com\/wp-json\/wp\/v2\/media?parent=10280"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/3cloudsolutions.com\/wp-json\/wp\/v2\/categories?post=10280"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/3cloudsolutions.com\/wp-json\/wp\/v2\/tags?post=10280"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}