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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
rgalvez
Frequent Visitor

Working hours with UTC times

Hello experts!

 

I have two tables:
Table 1 has all the users list, which includes the time zone where each user lives.  Table 2 has a completion date for each user. Many completions per user, in UTC format.   Tables are linked one-to-many through the UserID.

Table 1 (one):

UserIDUser NameTime Zone
1John DoeEST
2Jane DoeCST
3Jack DoePST

 

Table 2 (many):

UserIDCompleted Date
15/9/2023 3:30:11 AM
26/13/2023 8:15:25 PM
38/12/2022 7:08:10 PM


I need to calculate, based on the user timezones, which completed dates happened after working hours for each user, consdering the end of the day at 6:00 pm.

Examples:

- UserID 2, lives in CST time (UTC -6). The user completed the task on 6/13/2023 at 8:15 PM (UTC),  which means the user completed the task at 2:15 pm (CST), which falls in working hours for the user.

 

- UserID 1, lives in PST time (UTC -8). The user completed the task on 5/9/2023 at 3:30 AM (UTC),  which means the user completed the task at 7:30 PM (PST of the previous day), which falls out of working hours for the user.

 

My challenge is to calculate which completed dates fall out of working hours.

 

Thanks for your support!

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

Hi @rgalvez 

1.You can create a new table(TimeZone) as follows:

vxinruzhumsft_0-1687486116891.png

2.Then create a one-many relationship between timezone table and table 1

vxinruzhumsft_3-1687486440376.png

 

3.Then create a calculated column in table 2

IfOvertime =
VAR a =
    RELATED ( 'TimeZone'[Timedifference] )
VAR b =
    CONVERT (
        FORMAT ( 'Table 2'[Completed Date] - TIME ( a, 0, 0 ), "General Date" ),
        DATETIME
    )
VAR c =
    CONVERT ( DATEVALUE ( b ) & " " & TIME ( 18, 0, 0 ), DATETIME )
RETURN
    IF ( b > c, "Yes", "No" )

Output

vxinruzhumsft_4-1687486609782.png

Best Regards!

Yolo Zhu

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

 

 

View solution in original post

2 REPLIES 2
rgalvez
Frequent Visitor

Hi Yolo!  This worked like a charm.  Thank you so much!

v-xinruzhu-msft
Community Support
Community Support

Hi @rgalvez 

1.You can create a new table(TimeZone) as follows:

vxinruzhumsft_0-1687486116891.png

2.Then create a one-many relationship between timezone table and table 1

vxinruzhumsft_3-1687486440376.png

 

3.Then create a calculated column in table 2

IfOvertime =
VAR a =
    RELATED ( 'TimeZone'[Timedifference] )
VAR b =
    CONVERT (
        FORMAT ( 'Table 2'[Completed Date] - TIME ( a, 0, 0 ), "General Date" ),
        DATETIME
    )
VAR c =
    CONVERT ( DATEVALUE ( b ) & " " & TIME ( 18, 0, 0 ), DATETIME )
RETURN
    IF ( b > c, "Yes", "No" )

Output

vxinruzhumsft_4-1687486609782.png

Best Regards!

Yolo Zhu

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

 

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.