Forum Discussion

Clampazzo's avatar
Clampazzo
Icon for Resolver I rankResolver I
1 year ago

Set TImeZone to user's browser timezone in Embedded

We currently have an apps own data embedded setup of Power BI.  Our Models are currently showing all users date/times based on EST.  However, we would like to modify this so that it will adjust the timezone to reflect where the user is logged in from.  

So for instance if a user logs in from California it would set a offset of -3 on all times in the model.  

 

The model in question has a datetime dimension that is connected to the fact table.  One model is also shared across multiple clients with RLS applied to keep the data separated.  

 

What are some methods that could accomplish this?

 

I am looking into using javascript to pass the user's timezone to embedded to utilize as was mentioned in this article:  https://forum.enterprisedna.co/t/retrieve-user-timezone/69436

I can get an alert to show the timezone being used when loading the embedded report


However, I am unsure how to capitalize on this within Power BI.  Below is the code that is used to embed the report within javascript.  

I do have a table named "TimeZone" in my model with a column named "UserTimeZone" in it

let userTimeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
console.log(userTimeZone);
alert(userTimeZone);
var embedConfig = {
    accessToken: _selectedReport.EmbedConfig.EmbedToken.Token,
    embedUrl: _selectedReport.EmbedConfig.EmbedUrl,
    id: _selectedReport.EmbedConfig.Id,
    type: 'report',
    tokenType: models.TokenType.Embed,
    permissions: models.Permissions.ReadWrite,
    viewMode: models.ViewMode.View,
    settings: {
        panes: {
            filters: {
                expanded: false
            }
        },
        filters: [
            {
                $schema: "http://powerbi.com/product/schema#advanced",
                target: {
                    table: "TimeZone",
                    column: "UserTimeZone"
                },
                operator: "In",
                values: [userTimeZone]
            }
        ]
    }
};

 



2 Replies

  • Hi Clampazzo 

     

    The way I have gone about this for other clients is to create multiple date columns with the daytime offset based on their location. I then have a Sliver in the report page, which will then allow them to select the time zone that they are in and all the corresponding data will then change to that time zone.

    • Clampazzo's avatar
      Clampazzo
      Icon for Resolver I rankResolver I

      Hi GilbertQ , I'm looking into doing this now.  This could be a solution for my issue.  Do you happen to have an example as to how you did this?  When I attempted to do this I either get a very slow measure or something that doesn't work.  

      I did create a table that I named "Timezone Offset" with just 2 columns Timezone and Offset like below

      Timezone    Offset

      EST                  0
      CST                  -1
      PST                  -3

      I then created this measure to determine which one a user selects if the pull the "Timezone" field into a slicer

      SelectedTimezoneOffset = 
      VAR SelectedOffset = SELECTEDVALUE('Timezone Offset'[Offset], 0)
      RETURN SelectedOffset


      I then created this measure in my datetime table to try and allow a user to adjust the timezone on the fly... but this isn't working, visual returned a query exceeded resources error

      AdjustedDateTime 2 = 
      VAR Offset = [SelectedTimezoneOffset]
      RETURN 
          MAX('Create DateTime'[Creation DateTime]) + Offset / 24