Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Applicable88
Impactful Individual
Impactful Individual

Get the right date from time switch zone function

Hello,

 

I use this function to work against the utc+2 time lap:

Time.Hour(DateTimeZone.SwitchZone(DateTimeZone.LocalNow(),2,0))

 

I have different calculation based on different times.

I wanted to get the right day as well. For example when its already 1am the server is still 23:00.

And so I need a function which not tells me the time.hour but the day whe are in, including the time lap of course.

When I do the following I always get year 1899:

 

Date.From(DateTimeZone.SwitchZone(DateTimeZone.LocalNow(),2,0))

 

Is there a workaround to get the "right" day from client point of view?

 

Thank you in advance.

Best. 

 

1 ACCEPTED SOLUTION
v-kelly-msft
Community Support
Community Support

Hi  @Applicable88 ,

 

Use below M code to get the right day:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwMtQ31TcyUDA0sDIyc/RVio0FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Datetime = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Datetime", type datetime}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each DateTimeZone.SwitchZone(DateTimeZone.From(DateTime.LocalNow()),2,0)),
in
   #"Added Custom"

DateTimeZone.SwitchZone(DateTimeZone.From(DateTime.LocalNow()),2,0)

 

pls check my .pbix file attahched.

 

Best Regards,
Kelly

Did I answer your question? Mark my post as a solution!

View solution in original post

2 REPLIES 2
v-kelly-msft
Community Support
Community Support

Hi  @Applicable88 ,

 

Use below M code to get the right day:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwMtQ31TcyUDA0sDIyc/RVio0FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Datetime = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Datetime", type datetime}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each DateTimeZone.SwitchZone(DateTimeZone.From(DateTime.LocalNow()),2,0)),
in
   #"Added Custom"

DateTimeZone.SwitchZone(DateTimeZone.From(DateTime.LocalNow()),2,0)

 

pls check my .pbix file attahched.

 

Best Regards,
Kelly

Did I answer your question? Mark my post as a solution!

thanks @v-kelly-msft !

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors