The ultimate Microsoft Fabric, Power BI, Azure AI, and SQL learning event: Join us in Stockholm, September 24-27, 2024.
Save €200 with code MSCUST on top of early bird pricing!
Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started
Hey all, this isn't actually a question but something I created which may help others that find themselves in a similar situation.
Below is code to create a custom column with the number of hours needed to switch a UTC column to Aus EST, taking into account daylight savings.
Steps:
Hopefully this helps. I've only run this on a smallish dataset (18 months of data) so I've not done a huge amount of testing but I've not encountered any issues as of yet. However, open to improvement suggestions!
Thanks,
John
if Date.Month(DateTimeZone.SwitchZone([orderDate], 10)) = 4 and
(Date.DayOfWeekName(DateTimeZone.SwitchZone([orderDate], 10)) = "Sunday" and Date.Day(DateTimeZone.SwitchZone([orderDate], 10)) <= 7 and Date.Day(DateTimeZone.SwitchZone([orderDate], 10)) > 1
or Date.DayOfWeekName(DateTimeZone.SwitchZone([orderDate], 10)) = "Sunday" and Date.Day(DateTimeZone.SwitchZone([orderDate], 10)) = 1 and DateTime.Time(DateTimeZone.SwitchZone([orderDate], 10)) > #time(3,0,0)
or Date.Day(DateTimeZone.SwitchZone([orderDate], 10)) >= 7
or Date.DayOfWeekName(DateTimeZone.SwitchZone([orderDate], 10)) = "Monday" and List.Contains({2, 3, 4, 5, 6}, Date.Day(DateTimeZone.SwitchZone([orderDate], 10)))
or Date.DayOfWeekName(DateTimeZone.SwitchZone([orderDate], 10)) = "Tuesday" and List.Contains({3, 4, 5, 6}, Date.Day(DateTimeZone.SwitchZone([orderDate], 10)))
or Date.DayOfWeekName(DateTimeZone.SwitchZone([orderDate], 10)) = "Wednesday" and List.Contains({4, 5, 6}, Date.Day(DateTimeZone.SwitchZone([orderDate], 10)))
or Date.DayOfWeekName(DateTimeZone.SwitchZone([orderDate], 10)) = "Thursday" and List.Contains({5, 6}, Date.Day(DateTimeZone.SwitchZone([orderDate], 10)))
or Date.DayOfWeekName(DateTimeZone.SwitchZone([orderDate], 10)) = "Friday" and Date.Day(DateTimeZone.SwitchZone([orderDate], 10)) = 6
or Date.Day(DateTimeZone.SwitchZone([orderDate], 10)) >= 7) then 10
else if Date.Month(DateTimeZone.SwitchZone([orderDate], 10)) = 10 and
(Date.DayOfWeekName(DateTimeZone.SwitchZone([orderDate], 10)) = "Sunday" and Date.Day(DateTimeZone.SwitchZone([orderDate], 10)) <= 7 and Date.Day(DateTimeZone.SwitchZone([orderDate], 10)) > 1
or Date.DayOfWeekName(DateTimeZone.SwitchZone([orderDate], 10)) = "Sunday" and Date.Day(DateTimeZone.SwitchZone([orderDate], 10)) = 1 and DateTime.Time(DateTimeZone.SwitchZone([orderDate], 10)) > #time(3,0,0)
or Date.Day(DateTimeZone.SwitchZone([orderDate], 10)) >= 7
or Date.DayOfWeekName(DateTimeZone.SwitchZone([orderDate], 10)) = "Monday" and List.Contains({2, 3, 4, 5, 6}, Date.Day(DateTimeZone.SwitchZone([orderDate], 10)))
or Date.DayOfWeekName(DateTimeZone.SwitchZone([orderDate], 10)) = "Tuesday" and List.Contains({3, 4, 5, 6}, Date.Day(DateTimeZone.SwitchZone([orderDate], 10)))
or Date.DayOfWeekName(DateTimeZone.SwitchZone([orderDate], 10)) = "Wednesday" and List.Contains({4, 5, 6}, Date.Day(DateTimeZone.SwitchZone([orderDate], 10)))
or Date.DayOfWeekName(DateTimeZone.SwitchZone([orderDate], 10)) = "Thursday" and List.Contains({5, 6}, Date.Day(DateTimeZone.SwitchZone([orderDate], 10)))
or Date.DayOfWeekName(DateTimeZone.SwitchZone([orderDate], 10)) = "Friday" and Date.Day(DateTimeZone.SwitchZone([orderDate], 10)) = 6
or Date.Day(DateTimeZone.SwitchZone([orderDate], 10)) >= 7)
then 11
else null
Solved! Go to Solution.
In short,
- it repeatedly adds 10 hours to the UTC time (which is the minimum number of hours NSW is ahead of UTC)
- then checks whether the new date is in April or October and whether the date is either the 1st Sunday in the month (and what time) or a day after
- it then returns 10 (April) or 11 (October) to be used to convert the UTC time which you then use to update the original UTC
In short,
- it repeatedly adds 10 hours to the UTC time (which is the minimum number of hours NSW is ahead of UTC)
- then checks whether the new date is in April or October and whether the date is either the 1st Sunday in the month (and what time) or a day after
- it then returns 10 (April) or 11 (October) to be used to convert the UTC time which you then use to update the original UTC
Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.
Check out the August 2024 Power BI update to learn about new features.
Learn from experts, get hands-on experience, and win awesome prizes.
User | Count |
---|---|
20 | |
18 | |
18 | |
14 | |
13 |
User | Count |
---|---|
40 | |
32 | |
22 | |
19 | |
18 |