Forum Discussion
Timezone conversion issues in PowerQuery
- 2 years ago
I've figured it out!
It's because NZ summer wraps around the new year.So I need to calculate WinterTime instead and adjust the calculation like so:
(datetimecolumn as datetime) => let date = DateTime.Date(datetimecolumn), time = DateTime.Time(datetimecolumn), ForwardDate = Date.StartOfWeek(#date(Date.Year(date), 9, 30), Day.Sunday), BackDate = Date.StartOfWeek(#date(Date.Year(date), 4, 7), Day.Sunday), isWinterTime = (date = BackDate and time >= #time(2,0,0)) or (date > BackDate and date < ForwardDate) or (date = ForwardDate and time < #time(2,0,0)), timeZone = 13 - Number.From(isWinterTime), NZ_time = DateTime.From(date) + #duration(0,Time.Hour(time),Time.Minute(time),Time.Second(time)) + #duration(0, timeZone, 0, 0) in NZ_time
You should know when DST starts and ends for your location. Use these datetimes for the cutoff.
Or - preferably - do everything in UTC always, and then let the report user's browser do the conversion.
- onlycallisto2 years agoFrequent Visitor
But I have put in the DST dates for my location - I've defined them in the ForwardDate and BackDate fields.
But for some reason the isSummerTime function is only returning TRUE if the date is exactly the ForwardDate, as if it is only reading the first expression in its definition and ignoring all the or's and and's.
I can't work in UTC if PowerQuery is interpreting my dates as being in NZ time instead of UTC. It's importing them incorrectly so I have to fix it manually.- lbendlin2 years agoSuper User
isSummerTime = (datetimecolumn > ForwardDate & #duration(0,2,0,0)) or (datetimecolumn < BackDate & #duration(0,2,0,0)),- onlycallisto2 years agoFrequent Visitor
That doesn't work, they're not compatible.
I tried it with + instead of & and it also doesn't work for a different reason: