Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Local Time on Power BI Service

Tags:

powerbi

dax

As you all might already know, TODAY() function returns UTC time when published to Power BI Service. Our requirement is to return the local (EST) date. As a solution, we created a custom measure that adds UTC offset hours for EST in NOW() and returns the resultant date.

However, this does not handle daylight saving changes as offset changes during these periods.

What are the possible ways to handle this?

like image 760
Pratik Bhavsar Avatar asked Jun 23 '20 04:06

Pratik Bhavsar


People also ask

What is the time in the Power BI service?

In Power BI, if you have been using date and time data for long enough, you may have noticed a peculiarity with how your time works in Power BI Desktop, compared to Power BI Service. This is because Power BI Desktop uses your computer's local time, whereas Power BI Service uses UTC time.


1 Answers

You can try something like this:

ESTnow=
VAR currentTime = NOW()
VAR timeYear = YEAR(currentTime)

VAR dstStart = DATE(timeYear, 03, 14 - MOD((1+FLOOR(timeYear*5/4,1)),7)) + TIME(2,0,0)
VAR dstEnd = DATE(timeYear, 11, 7 - MOD((1+FLOOR(timeYear*5/4,1)),7)) + TIME(2,0,0)

RETURN IF(currentTime >= dstStart && currentTime <= dstEnd, currentTime - TIME(4,0,0), currentTime - Time(5,0,0))

Daylight savings start on the second Sunday of March and end on the first Sunday of November.

like image 99
Joao Leal Avatar answered Oct 06 '22 14:10

Joao Leal