Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago
Solved

Show Date/time based on user's time zone

Hi all, I have a date column and I want to show it dynamically based on the user's time zone.

 

I changed the format of the column to date/time/timezone and I thought Power Bi would handle it automatically but it didn't work.

How can I fix this problem? (I am using Azure blob storage as the source)

Thanks for your help in advance.

 

  • Hi Anonymous 

    While M has built-in functions to handle timezones, none of them automatically shifts to the user's. The service uses Utc while Desktop is the user's. M will not know what timezone those datetimes are in so any datetime column converted to datetimezone will be +0 if refreshed in the service. You can convert a datetime column to datetimezone with an offset value (like 10.5 for GMT+10:30) using DateTimeZone.AddZone but knowing what timezone to add is key. Either way, you get to select and load only a specific timezone - Utc or user-defined.

9 Replies

  • Hi Anonymous 

    While M has built-in functions to handle timezones, none of them automatically shifts to the user's. The service uses Utc while Desktop is the user's. M will not know what timezone those datetimes are in so any datetime column converted to datetimezone will be +0 if refreshed in the service. You can convert a datetime column to datetimezone with an offset value (like 10.5 for GMT+10:30) using DateTimeZone.AddZone but knowing what timezone to add is key. Either way, you get to select and load only a specific timezone - Utc or user-defined.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Thanks for your explanation.
    Is it possible to have a dropdown slicer and the user select the time zone?
    Afterward, all the data is reformatted and switched to the time zone selected by the user.

    • danextian's avatar
      danextian
      Super User

      Hi Anonymous 

      You can use a parameter where the user can select the timezone from and add that to the datetime value. Take note that the switched zone value has to be a measure as a calculated column will not recalculate in response to a slicer selection. A column that will return a distinct datetime must be added to the visual as measures do not have row context. For example, if you add category and category A has two or more datetime values then the measure will not show the correct value.  Alternatively, instead of using a slicer you can use USERPRINCIPALNAME() to return the current user's email in the service and use that to filter a predefined table of the  user email + the corresponding timezone. Please see attached pbix for the details

       

      • Anonymous's avatar
        Anonymous
        Not applicable

        Hi DAN,
        Thank you for your solution, but I faced another issue.
        I can't use measures for graph visuals, for example, the X-axis of a line chart.
        Is there any way to update the time zone based on user selection in graphs alongside tables?