View Categories

How to Import Salesforce Data into Microsoft Power BI

This guide walks you through connecting Power BI Connector for Salesforce to Microsoft Power BI Desktop, from creating an access token to loading Salesforce tables into a report.

You need three things from the connector app before you open Power BI: an access token, a data source, and the Power Query script the app generates for that data source. The sections below create them in that order, then use them in Power BI Desktop.

i
Want a finished dashboard instead of building one? The connector ships ten ready-made Power BI dashboards. See Dashboard Templates.

1. Create an Access Token #

An access token authorizes Power BI to read your data sources. It is tied to your Salesforce user, so Power BI sees exactly the records you can see.

Step 1: Open Access Tokens #

  • Open the Power BI Connector app in Salesforce.
  • In the left menu, click Access Tokens.
Access Tokens page in Power BI Connector

Step 2: Create the token #

  • Click Create token.
  • Enter a Label that tells you where the token is used, for example Power BI Desktop.
  • (Recommended) Set an Expiry date. The date cannot be changed after the token is created. If your administrator has enabled automatic expiry, a date is applied when you leave the field empty.
  • Click Create.
Create access token dialog

Step 3: Copy the token #

The token is shown once. Click the Copy button and keep the value somewhere safe until you paste it into Power BI in section 4.

Your new access token dialog
⚠ Important: You can view and copy the token only at this moment. If you lose it, create a new token. Treat the token like a password and do not share it.

You can revoke a token at any time from the Access Tokens page. Expired and revoked tokens stop working immediately; Power BI then needs a new token in its parameter (see Updating the token below).

2. Create a Data Source #

A data source is the set of Salesforce objects, fields and filters that Power BI will receive. Create it in the connector app under Data Sources → Create data source: give it a name, tick the objects you need, expand each object and select its fields, then click Save.

i
Every option of the data source editor (objects, fields, filters, SOQL mode, sharing, preview) is covered in How to Create Data Source. You can also build a data source from an existing Salesforce report, see How to Export Salesforce Reports and Joined Reports to Power BI.

After saving, the data source appears in the Data Sources list.

Data Sources list

3. Copy the Power Query Script #

Each data source has its own connection script. You copy it once here and paste it into Power BI in section 4.

  • In the Data Sources list, find your data source.
  • Click the Copy power query button at the right end of the row (the first of the two buttons). A Copied! message confirms the script is on your clipboard.
Copy power query button on a data source row

The script looks like this:

let
    Source = OData.Feed(
        "https://[your Site URL]/services/apexrest/metrica_powerbi/OAuthProxy/a01XXXXXXXXXXXX",
        [xUserKey = metricaToken]
    )
in
    Source

Where:

  • [your Site URL] is the Salesforce Site the connector is published on (for example https://your-company.my.salesforce-sites.com). The app fills it in for you.
  • a01XXXXXXXXXXXX is the ID of this data source. Every data source has a different one.
  • metricaToken is the name of the parameter you will create in Power BI Desktop to hold your access token. Keep the name exactly as it is.
i
The row menu (···) also has Copy URL, which copies only the data source URL. You need the URL, not the whole script, when you open a dashboard template.

4. Connect Power BI Desktop #

All of the following happens in the Power Query Editor, a separate window that Power BI Desktop opens on top of the report canvas. Keep it open until you reach Close & Apply in Step 6.

Step 1: Open a blank query #

  • Open Power BI Desktop and start a Blank report.
  • On the Home tab, open the Get data drop-down and click Blank query.
Get data menu with Blank query

The Power Query Editor opens with an empty query named Query1 in the Queries pane on the left.

Power Query Editor with Query1

Step 2: Create the token parameter #

The parameter keeps your token out of the query text, so you can replace the token later without touching the script.

  • On the Power Query Editor Home tab, click Manage Parameters → New Parameter.
  • Set Name to metricaToken (exactly as written, it is case-sensitive).
  • Leave Type as Text and Suggested Values as Any value.
  • Paste your access token into Current Value.
  • Click OK. The parameter appears in the Queries pane.
Manage Parameters dialog with the metricaToken parameter

Step 3: Paste the script #

  • In the Queries pane, select Query1.
  • On the Home tab, click Advanced Editor.
  • Delete the placeholder text, paste the script you copied in section 3, and click Done.
Advanced Editor with the connector script

Step 4: Choose Anonymous when asked #

The first time Power BI Desktop connects to a data source URL it asks how to authenticate, either in a dialog or through an Edit Credentials button above the preview.

  • Select Anonymous.
  • Leave the level as suggested (the Salesforce Site address).
  • Click Connect.
Authentication dialog with Anonymous selected
i
Anonymous is correct, not a workaround. Your access token travels inside the request, so Power BI has no username or password to store. Power BI remembers the choice for the whole Salesforce Site, so you see this dialog once per computer, not once per data source.

Step 5: Add each object as a table #

Query1 now shows one row per Salesforce object in the data source, with a Table link in the Data column.

  • Right-click the word Table next to an object and click Add as New Query.
  • Rename the new query to the object name, for example Account or Opportunity (right-click the query → Rename).
  • Go back to Query1 and repeat for every object you want in the report.
Add as New Query on a Table link

When you are done, the Queries pane lists the parameter, Query1 and one query per object:

Queries pane with Account and Opportunity added

Query1 itself does not need to load into the report. Right-click it and clear Enable load, or delete it once you have added all the tables.

Step 6: Close & Apply #

  • On the Home tab, click Close & Apply.
  • Power BI loads the data. The tables appear in the Data pane of the report, ready for visuals.
Close & Apply and the loaded tables

To pull fresh data from Salesforce later, click Refresh on the Home tab of the report.

5. Publish to the Power BI Service and Refresh Online #

A report published to the Power BI service refreshes online without a gateway. One setting is different from other data sources: the service cannot test the credentials, so you tell it to skip the test.

Step 1: Publish the report #

  • In Power BI Desktop, click Publish on the Home tab and choose a workspace.
  • In the Power BI service, open the workspace, find the semantic model that was published with the report, open its menu (···) and click Settings.

Step 2: Set the credentials with Skip test connection #

Expand Data source credentials. The service reports that it failed to test the connection. This is expected: the test sends a plain request without your token.

Data source credentials section before the credentials are set
  • Click Edit credentials.
  • Set Authentication method to Anonymous.
  • Tick Skip test connection.
  • Click Sign in.
Configure data source dialog with Anonymous and Skip test connection
⚠ Skip test connection is required. Without it the dialog refuses the credentials even though the refresh itself works. After you save, the section reads Some credentials aren’t validated as they are set to skip test connection, which is the correct state.

Step 3: Refresh #

Back in the workspace list, open the semantic model menu and click Refresh now. The refresh completes in a few seconds for a typical data source, and Refresh history on the settings page shows it as Completed. From here you can configure Scheduled refresh on the same settings page.

Refresh history showing a completed on-demand refresh
i
The credentials are stored per Salesforce Site, so other reports in the workspace that use data sources from the same site pick them up automatically.

6. Updating the Token #

When a token expires or is revoked, Power BI returns 400 Bad Request on the next refresh. Create a new token in the connector app and put it into the parameter:

  • Power BI Desktop: on the Home tab, open the Transform data drop-down → Edit parameters, paste the new token into metricaToken and click OK. Then Refresh.
  • Power BI service: open the semantic model Settings → Parameters, replace the value of metricaToken and click Apply. Then refresh the model.

The script itself never changes. Only the parameter value does.

Troubleshooting #

What you seeWhat it meansWhat to do
400 Bad Request, Missing user keyThe request reached Salesforce without a token.Check that the parameter is named metricaToken (case matters) and holds a current token. In the Power BI service, make sure the credentials were saved with Skip test connection (section 5).
400 Bad Request after the token worked beforeThe token expired or was revoked.Create a new token and update the parameter (section 6).
A credentials prompt that does not accept the tokenThe wrong authentication method is selected.Choose Anonymous. The token is a parameter, not a credential.
We expected a property … but the OData service omitted itA field the query uses is no longer in the data source.Edit the data source in the connector app and add the field back.
Empty tables, no errorThe data source filters exclude every record, or your Salesforce user cannot see the records.Check the filters on the data source and your object permissions.
Copy power query does nothingClipboard access is blocked in the browser.Allow clipboard access for your Salesforce domain, or open the data source and copy the script from there.
i
Still stuck? See Contact Support.