Forum Discussion
RZ89
4 years agoFrequent Visitor
Wrong date based on a timefilter in PowerQuery and SQL Data base
Hi everyone, I have a very strange behavior in an important report and cannot solve the issue. The reports is caltulating values based on demands in the past regarding current date. Example:...
jennratten
4 years agoSuper User
Hello - have you tried converting both dates before comparing? In this example, I used variables to create the local and requirement date and added 10 hours to each so that the requirement date would initially appear as tomorrow.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlSKjQUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
// Number of hours to force German time into tomorrow, just for this example.
varOffsetHours = 10,
// Local datetime + offset hours
varLocalDateTimeZone = DateTimeZone.ToLocal(DateTimeZone.FixedLocalNow() + #duration(0,varOffsetHours,0,0)),
// Requirement datetime + offset hours
varRequirementDateTimeZone = DateTimeZone.SwitchZone(DateTimeZone.UtcNow() + #duration(0,varOffsetHours,0,0),2,00),
// Get your local time.
LocalDateTimeZone = Table.AddColumn(Source, "LocalDateTimeZone", each varLocalDateTimeZone, type datetimezone),
RequirementDateTimeZone = Table.AddColumn(LocalDateTimeZone, "RequirementDateTimeZone", each varRequirementDateTimeZone, type datetimezone),
LocalDate = Table.AddColumn(RequirementDateTimeZone, "LocalDate", each Date.From([LocalDateTimeZone]), type date),
RequirementDateToLocalZone = Table.AddColumn(LocalDate, "RequirementDateInLocalZone", each Date.From(DateTimeZone.ToLocal([RequirementDateTimeZone])), type date)
in
RequirementDateToLocalZone
RZ89
4 years agoFrequent Visitor
Hi Jennratten,
thank you for your help. I tried to set up a column with localtime+Date and derivate it to a column with only the date. With adjustion of 2 hours before it seems to work perfect.
Thanks!!