Forum Discussion
How do I make my Power Query formula accept timezone with decimal points
Hi,
I want to create a Power Query Formula, which uses a Parameter that my users can manipulate called as Time Zone. The Parameter type for #Time Zone is decimal right now so it can accept positive & negative values with decimal points.
I have a 'datetime' column called Time in (UTC). I want to create a Power Query formula such that I can pass the parameter #Time Zone which would convert Time (UTC) column to match that time zone and update the values in the column.
Eg: if UTC datetime value is
| 8/20/2020 14:10:15 UTC |
and my #Time Zone is +5.5 (5:30 mins) then above value should change to 8/20/2020 7:40:15 PM (8/20/2020 19:40:15 IST)
or if my #Time Zone is -5 (5:00 ) then my time value should change to 8/20/2020 9:10:15 AM (8/20/2020 09:10:15 ET)
I may have to change the datatype of my #Time Zone parameter from decimal to time or duration according to soultion which is fine but I would prefer in Decimal.
5 Replies
- Jimmy801Community Champion
Hello newpi
You can use the function DateTimeZone.SwitchZone to accomplish this. This accepts a number to switch the zone. In case you want to use another format afterwards, you could create a function where you manipulate the format, before passing it to the function DateTimeZone.SwitchZone. Here the code
let Source = #table ( {"TimeZoneUTC"}, {{DateTimeZone.FixedUtcNow()}} ), Add= Table.AddColumn ( Source, "Your time", each DateTimeZone.SwitchZone([TimeZoneUTC],5.5) ) in AddCopy paste this code to the advanced editor in a new blank query to see how the solution works.
If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too
Have fun
Jimmy- newpiHelper V
Jimmy801 I want to use a parameter here and my parameter name is "#Time Zone" .
I do not want to add column as there are dependant columns to my existing one, so want to edit my formula there itself. My current formula is :
The above formula is working fine when #Time Zone Parameter is whole number like 5 but not working when its a decimal like 5.5
- Jimmy801Community Champion
Hello newpi
then change the formula to this
= if #"Daylight Savings" = true then DateTimeZone.SwitchZone([#"Activity Time (UTC)"],#"Time Zone" +1) else DateTimeZone.SwitchZone([#"Activity Time (UTC)"],#"Time Zone")
If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too
Have fun
Jimmy
- IceyCommunity Support