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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Domenick
Helper IV
Helper IV

How do I create a custom global function? (for time zone conversion)

I want to write a custom function to convert datetime from UTC to PST/PDT. Can someone point me in the right direction? I want to use the function across multiple reports. The only guidance I've found is file-specific.

 

Also would be cool if you just knew of an already existing function that easily converts to a different timezone; that would be great.

2 ACCEPTED SOLUTIONS
jdbuchanan71
Super User
Super User

@Domenick 

You can add a custom column in PowerQuery to adjust the UTC back like this.

[Date] + #duration(0,-8,0,0)

jdbuchanan71_0-1662574502625.png

 

View solution in original post

Domenick
Helper IV
Helper IV

I solved this by adding a Custom Column in Query Editor which brings the time in as UTC and converts it to PST or PDT based appropriately. The -7 and the -8 are the offset hours (Pacific time is either 7 or 8 hours behind UTC depending on the time of year). I strung this solution together with the help of this guidance by @Rickmaurinus : https://gorilla.bi/power-query/last-refresh-datetime/  

 

 

let
UTC_DateTimeZone = DateTimeZone.UtcNow(),
UTC_Date = Date.From(UTC_DateTimeZone),
StartSummerTime = Date.StartOfWeek(#date(Date.Year(UTC_Date), 3, 31), Day.Sunday),
StartWinterTime = Date.StartOfWeek(#date(Date.Year(UTC_Date), 10, 31), Day.Sunday),
UTC_Offset = if UTC_Date >= StartSummerTime and UTC_Date < StartWinterTime then -7 else -8,
PST_Timezone = DateTimeZone.SwitchZone(UTC_DateTimeZone, UTC_Offset)
in
PST_Timezone

View solution in original post

6 REPLIES 6
jdbuchanan71
Super User
Super User

Nice, thank you for sharing your final solution @Domenick .

Domenick
Helper IV
Helper IV

I solved this by adding a Custom Column in Query Editor which brings the time in as UTC and converts it to PST or PDT based appropriately. The -7 and the -8 are the offset hours (Pacific time is either 7 or 8 hours behind UTC depending on the time of year). I strung this solution together with the help of this guidance by @Rickmaurinus : https://gorilla.bi/power-query/last-refresh-datetime/  

 

 

let
UTC_DateTimeZone = DateTimeZone.UtcNow(),
UTC_Date = Date.From(UTC_DateTimeZone),
StartSummerTime = Date.StartOfWeek(#date(Date.Year(UTC_Date), 3, 31), Day.Sunday),
StartWinterTime = Date.StartOfWeek(#date(Date.Year(UTC_Date), 10, 31), Day.Sunday),
UTC_Offset = if UTC_Date >= StartSummerTime and UTC_Date < StartWinterTime then -7 else -8,
PST_Timezone = DateTimeZone.SwitchZone(UTC_DateTimeZone, UTC_Offset)
in
PST_Timezone

Domenick, 

 

I think the function you used is the easiest approach. At this point we can't make it a global function though. I hope the Microsoft Team will release a functionality that does support this in the future. 

 

Until then, save the query somewhere or copy it from the blogpost 🙂

 

Enjoy!

Rick

--------------------------------------------------

@ me in replies or I'll lose your thread

 

Master Power Query M? -> https://powerquery.how

Read in-depth articles? -> BI Gorilla

Youtube Channel: BI Gorilla

 

If this post helps, then please consider accepting it as the solution to help other members find it more quickly.

jdbuchanan71
Super User
Super User

No, because UTC is not affected by daylight saving time.

jdbuchanan71
Super User
Super User

@Domenick 

You can add a custom column in PowerQuery to adjust the UTC back like this.

[Date] + #duration(0,-8,0,0)

jdbuchanan71_0-1662574502625.png

 

Will that account for daylight savings?

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

Fabric Community Sticker Design Challenge Barcelona Carousel

Fabric Community Sticker Challenge - Barcelona 2026

If you love stickers, then you will definitely want to check out our community sticker challenge, Barcelona edition!

July Power BI Update Carousel

Power BI Monthly Update - July 2026

Check out the July 2026 Power BI update to learn about new features.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors