Forum Discussion
Applying a duration to DateTime
Hello Gurus,
I'm a newbie in Power BI. I just want to ask if my below syntax is correct. I just want to create a custom column on which I want to apply a duration of +8 hours since Power BI is not showing the correct Date and Time (Timezone).
Dates below Nov 11, 2022 are all displayed correctly. However, the dates greater that Nov 15, 2022 are all in UTC format. Thanks in advance.
===
= Table.AddColumn(#"Changed Type1", "PHCreatedDateTime", each if DateTime.From([Created]) > #datetime(2022,11,11,0,0,0) as datetime then DateTime.From([Created]) + #duration(0,8,0,0) else null)
===
Hello again Anonymous
I got it now Sir. Instead of null, I just put the DateTime.From([Created]) after else.... Many thanks again. Cheers! 🍻
= Table.AddColumn( #"Changed Type1", "PHCreatedDateTime", each
if DateTime.From([Created]) > #datetime(2022,11,11,0,0,0)
then DateTime.From([Created]) + #duration(0,8,0,0) else DateTime.From([Created]), type datetime)
3 Replies
- AnonymousNot applicable
Hi rakeman23 - I you thinking along the right line but I think you need to remove "as datetime"
= Table.AddColumn( #"Changed Type1", "PHCreatedDateTime", each if DateTime.From([Created]) > #datetime(2022,11,11,0,0,0) then DateTime.From([Created]) + #duration(0,8,0,0) else null , type datetime)- rakeman23New Member
Hi Anonymous
Thanks Sir... worked like a charm 🙂
Although the "null" at the end of the statement, made the dates null.. hehe.. Sorry, what I want is for the statement to do "nothing" instead of null so that it will preserve its value
Apologies for the confusion. What should I substitute to null? Many thanks again- rakeman23New Member
Hello again Anonymous
I got it now Sir. Instead of null, I just put the DateTime.From([Created]) after else.... Many thanks again. Cheers! 🍻
= Table.AddColumn( #"Changed Type1", "PHCreatedDateTime", each
if DateTime.From([Created]) > #datetime(2022,11,11,0,0,0)
then DateTime.From([Created]) + #duration(0,8,0,0) else DateTime.From([Created]), type datetime)