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
DMB90
Helper II
Helper II

Adjust Power BI Query Time to be Dynamic with Daylight Savings Begins/Ends Formulas

I'm attempting to account for Daylight Savings Begins/Ends in my Time Refresher and was successful until I got to this part. I use Pacific Standard Time (United States) so need to subtract hours instead of adding. 

 

I used this video and was successful until this part at the 13 minute mark. This person is using time outside of the US.

 

What I think my formula should look like.

Time Refresh.png

 

Can I possibly edit CurrentDateTime here to be minus, so then I can just add hours to my if CurrentDateTime formula.

 

CurrentDateTime.png

1 ACCEPTED SOLUTION
jgeddes
Super User
Super User

DateTimeZone.SwitchZone() will accept negative numbers.
Here is a small example...

let
    spring_forward_utc = #datetimezone(2025,3,9,10,0,0,0,0),
    example_table =
    #table(
        {"dateTimeUTC"},
        {
            {#datetimezone(2025,3,9,09,59,32,0,0)},
            {#datetimezone(2025,3,9,10,00,35,0,0)}
        }
    ),
    change_type = 
    Table.TransformColumnTypes(
        example_table,
        {{"dateTimeUTC", type datetimezone}}
    ),
    add_local = 
    Table.AddColumn(
        change_type, 
        "Local Time", 
        each 
        if [dateTimeUTC] >= spring_forward_utc
            then DateTimeZone.SwitchZone([dateTimeUTC], -7)
            else DateTimeZone.SwitchZone([dateTimeUTC], -8),
        type datetimezone
    )
in
    add_local




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

Proud to be a Super User!





View solution in original post

1 REPLY 1
jgeddes
Super User
Super User

DateTimeZone.SwitchZone() will accept negative numbers.
Here is a small example...

let
    spring_forward_utc = #datetimezone(2025,3,9,10,0,0,0,0),
    example_table =
    #table(
        {"dateTimeUTC"},
        {
            {#datetimezone(2025,3,9,09,59,32,0,0)},
            {#datetimezone(2025,3,9,10,00,35,0,0)}
        }
    ),
    change_type = 
    Table.TransformColumnTypes(
        example_table,
        {{"dateTimeUTC", type datetimezone}}
    ),
    add_local = 
    Table.AddColumn(
        change_type, 
        "Local Time", 
        each 
        if [dateTimeUTC] >= spring_forward_utc
            then DateTimeZone.SwitchZone([dateTimeUTC], -7)
            else DateTimeZone.SwitchZone([dateTimeUTC], -8),
        type datetimezone
    )
in
    add_local




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

Proud to be a Super User!





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.