Retrieve User Timezone

Hi Everyone,
Is it possible to retrieve the timezone of a Power BI report user?
I’ve tried using TimeZone.Current, but it always returns Western Europe Standard Time, which I assume is the timezone where the Power BI Service is located.
Thanks for help
Roberto

Hi @Roberto

Using DataMentor/EDNA AI tools built within the EDNA Learning Portal. You can find a solution to your problem.

Here what comes up on DataMentor:

Retrieving the user’s timezone directly in Power BI is not straightforward because Power BI does not natively support capturing user environment details such as timezone.

However, you can consider a workaround using Power Automate or by custom embedding of Power BI reports within an application where you can pass user context to the report. Here are the approaches:

Approach 1: Using Power Automate

  1. Create a Power Automate Flow:
  • Trigger the flow when the user views the report.
  • Capture the user’s timezone using appropriate connectors (e.g., Office 365 Users connector).
  1. Pass the Captured Timezone to Power BI:
  • Once you have the user’s timezone from the flow, you can pass it to Power BI using the Power BI REST API or updating a dataset directly.

Approach 2: Custom Embedding

  1. Embed Report in a Web Application:
  • Create a web application to embed your Power BI report.
  • Capture the user’s timezone using JavaScript (Intl.DateTimeFormat().resolvedOptions().timeZone).
  1. Pass Timezone to Power BI Report:
  • Use Power BI JavaScript API to pass the timezone as a filter or parameter to the embedded report.

Example Using Power Automate (High-Level Steps):

  1. Create a Manual Triggered Flow in Power Automate.
  2. Add Get User Profile (V2) action to retrieve the user’s details.
  3. Extract the timezone from the user’s profile.
  4. Update a Power BI dataset/table with the timezone information using Power BI actions or Azure SQL connections.

Example Using JavaScript in Custom Embedding:

<script src="https://cdnjs.cloudflare.com/ajax/libs/powerbi-client/2.10.0/powerbi.min.js"></script>
<script>
  // Capture user's timezone
  let userTimeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
  
  // Configuration for embedding the report
  let embedConfiguration = {
    type: 'report',
    id: 'your-report-id',
    embedUrl: 'your-embed-url',
    accessToken: 'your-access-token',
    ...,
    settings: {
      ...
      filters: [
        {
          $schema: "http://powerbi.com/product/schema#advanced",
          target: {
            table: "YourTable",
            column: "TimezoneColumn"
          },
          operator: "In",
          values: [userTimeZone]
        }
      ]
    }
  };

  // Embed the report
  let reportContainer = document.getElementById('reportContainer');
  powerbi.embed(reportContainer, embedConfiguration);
</script>

These approaches require additional setup but will allow you to tailor the experience based on the user’s timezone.

Please give DataMentor a try!!!
I hope this helps.

Keith

1 Like