> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cognite.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Power BI OData connector

> Connect a Cognite Data Fusion project as a data source in Power BI using the OData connector.

<Warning>
  **Deprecated - For existing reports only**: This connector only supports Azure Entra ID and lacks access to newer CDF features. **All new reports must use the [REST API connector](/cdf/dashboards/guides/powerbi/set_up_rest_connector)**. The REST API connector supports all identity providers supported in CDF, better performance, and access to all CDF features.

  See the [migration guide](#migration-guide).
</Warning>

Before users can sign in with their organizational ID and retrieve data from <span translate="no">CDF</span>, an administrator must register and consent for your organization to use [<span translate="no">**Microsoft Power Query for Excel**</span>](/cdf/dashboards/guides/powerbi/admin) app registration.

<a id="setup-a-connection-to-cognite-data-fusion" />

## Connect to <span translate="no">Cognite Data Fusion</span> from Power Query Desktop

Follow these steps to connect a <span translate="no">Cognite Data Fusion (CDF)</span> project as a data source in <span translate="no">Power BI</span>.

<Steps>
  <Step title="Sign in to Power BI Desktop">
    In <span translate="no">**Power BI Desktop**</span>, sign in with your organization account.
  </Step>

  <Step title="Select the Cognite Data Fusion OData connector">
    On the **Home** tab, select **Get Data** and then **More**. In the **Get Data** dialog, search for **Cognite** and select the **Cognite Data Fusion (Odata)** connector.

    <Frame>
      <img src="https://apps-cdn.cogniteapp.com/@cognite/docs-portal-images/1.0.0/images/cdf/dashboards/powerbi/update2024/OData1.png" alt="Locate the CDF OData connector in Power BI" width="80%" />
    </Frame>
  </Step>

  <Step title="Configure the connection details">
    In the dialog box, enter details to configure the connection to <span translate="no">CDF</span>:

    * <span class="ui-element">Data Source Identifier</span>: Enter the <span translate="no">CDF</span> project name, a data model URL, or a custom <span translate="no">OData</span> query to retrieve data from <span translate="no">CDF</span>. This is a required field.

      To authenticate as a guest user in <span translate="no">Entra ID</span>, add the <span translate="no">Entra ID</span> tenant ID, for example, `dataSource?tenantId=MyEntraIDTenant.onmicrosoft.com`.

      If you're passing a custom <span translate="no">OData</span> URL that already contains query parameters, then you can add the `tenantId` at the end with this syntax: `dataSource?$filter={Filter}&tenantId=MyEntraIDTenant.onmicrosoft.com`.

    * <span class="ui-element">CDF API URL</span>: Enter the URL to the <span translate="no">Cognite</span> API, for example, `https://api.cognitedata.com` or `https://az-eastus-1.cognitedata.com`. To access some OData services, you might also need to add the API version, for example, `https://bluefield.cognitedata.com/20230821`.

    <Frame>
      <img src="https://apps-cdn.cogniteapp.com/@cognite/docs-portal-images/1.0.0/images/cdf/dashboards/powerbi/update2024/OData2_v1.png" alt="Configure the CDF OData connector in Power BI" width="80%" />
    </Frame>
  </Step>

  <Step title="Authenticate with your account">
    When prompted, sign in with your <span translate="no">Entra ID</span> account credentials.
  </Step>

  <Step title="Connect to the data source">
    Select <span class="ui-element">Connect</span> to open the <span class="ui-element">Navigator</span> window.
  </Step>

  <Step title="Select the data to load">
    Select the data you want to load or transform. For example, select the **Assets** table.
  </Step>

  <Step title="Load or transform data">
    Select **Load** to import the data directly or **Transform Data** to open the <span translate="no">Power Query editor</span> for data filtering and transformation.
  </Step>
</Steps>

<a id="connect-to-cognite-data-fusion-from-power-query-online" />

## Connect to <span translate="no">Cognite Data Fusion</span> from Power Query Online

Follow these steps to connect to CDF from Power Query Online.

<Steps>
  <Step title="Select Cognite Data Fusion OData">
    Select **Cognite Data Fusion (OData)** under <span class="ui-element">Get data</span>. See [Where to get data](https://learn.microsoft.com/en-us/power-query/where-to-get-data) for finding <span class="ui-element">Get data</span> in Power Query Online.

    <Frame>
      <img src="https://apps-cdn.cogniteapp.com/@cognite/docs-portal-images/1.0.0/images/cdf/dashboards/powerbi/online/odata/online-get-data-new.png" alt="Screenshot of the get data window with Cognite Data Fusion (OData) emphasized." width="80%" />
    </Frame>
  </Step>

  <Step title="Configure connection settings">
    In **Connection settings**, enter the following information:

    * <span class="ui-element">Data Source Identifier</span>: Enter the <span translate="no">CDF</span> project name, a data model URL, or a custom <span translate="no">OData</span> query to retrieve data from <span translate="no">CDF</span>.
      * To authenticate as a guest user in <span translate="no">Entra ID</span>, add the <span translate="no">Entra ID</span>  tenant ID, for example, `dataSource?tenantId=MyEntraIDTenant.onmicrosoft.com`.
      * If you're passing a custom <span translate="no">OData</span> URL that already contains query parameters, then you can add the `tenantId` at the end with this syntax: `dataSource?$filter={Filter}&tenantId=MyEntraIDTenant.onmicrosoft.com`.
    * <span class="ui-element">CDF API URL</span>: Enter the URL to the Cognite API, for example, `https://api.cognitedata.com` or `https://az-eastus-1.cognitedata.com`. To access some <span translate="no">OData</span> services, you might also need to add the API version, for example, `https://bluefield.cognitedata.com/20230821`.

    <Frame>
      <img src="https://apps-cdn.cogniteapp.com/@cognite/docs-portal-images/1.0.0/images/cdf/dashboards/powerbi/online/odata/online-connection-settings.png" alt="Screenshot of the Cognite Data Fusion (OData) online connection settings." width="80%" />
    </Frame>
  </Step>

  <Step title="Enter connection credentials">
    In **Connection credentials**, enter the following information:

    * If you're connecting to <span translate="no">CDF</span> for the first time, select <span class="ui-element">Create new connection</span> under <span class="ui-element">Connection</span>.

    * If you've connected previously, select an existing connection under <span class="ui-element">Connection</span>.

    * For <span class="ui-element">Data gateway</span>: If your organization uses a gateway to access <span translate="no">CDF</span>, select the appropriate gateway from the menu. If <span class="ui-element">Data gateway</span> is set to **(none)**, the connector uses the Power BI service to connect to <span translate="no">CDF</span> directly.

    * You can also select <span class="ui-element">Privacy Level</span> for the data connection.

    * For new connections, select **Sign in** and follow the authentication process.

    <Frame>
      <img src="https://apps-cdn.cogniteapp.com/@cognite/docs-portal-images/1.0.0/images/cdf/dashboards/powerbi/online/odata/online-connection-credentials.png" alt="Screenshot of the Cognite Data Fusion (OData) online connection credentials." width="80%" />
    </Frame>
  </Step>

  <Step title="Proceed after authentication">
    Select **Next** when you've signed in.
  </Step>

  <Step title="Choose and create data connection">
    In **Choose data**, select the data you require, then select **Create** to open the <span translate="no">Power Query editor</span> and retrieve data from <span translate="no">CDF</span>.

    <Frame>
      <img src="https://apps-cdn.cogniteapp.com/@cognite/docs-portal-images/1.0.0/images/cdf/dashboards/powerbi/online/odata/online-navigator.png" alt="Screenshot of the Power Query Online Navigator showing the available tables." width="80%" />
    </Frame>
  </Step>
</Steps>

<a id="filtering-data" />

### Filter data

Use **Transform Data** to apply filters and reduce the amount of data loaded into <span translate="no">Power BI</span>.

<a id="scheduled-refresh" />

### Scheduled refresh

After publishing your report to the <span translate="no">Power BI</span> service, you can schedule data refreshes to keep your data current.

<a id="data-model-urls" />

### Data model URLs

If you're using data models, make sure <span class="ui-element">Data Source Identifier</span> includes the correct data model URL. See [Data modeling OData service](/cdf/dashboards/references/odata/dm_odata).

<a id="custom-queries" />

### Custom queries

Enter custom <span translate="no">OData</span> queries in <span class="ui-element">Data Source Identifier</span> to retrieve specific data sets. See [Custom OData queries](/cdf/dashboards/references/odata/custom_queries).

<a id="migration-guide" />

## Migrate to the REST API connector

Migrate existing Power BI reports from the OData connector to the REST API connector. This involves updating the Power Query code at the beginning of each data query.

### Understand the differences

The OData connector uses the function signature `Cognite.Contents` and directly accesses tables through URL manipulation:

```js theme={"languages":{"custom":["/_languages/kuiper.json","../_languages/kuiper.json"]}}
let
    CogniteCDMViews = Cognite.Contents(
        "publicdata/models/spaces/cdf_cdm/datamodels/CogniteCore/versions/v1",
        "https://api.cognitedata.com/20230821"
    ),
    CogniteTimeSeriesTable = CogniteCDMViews{[Name = "CogniteTimeSeries", Signature = "table"]}[Data]
in
    CogniteTimeSeriesTable
```

The REST API connector uses the function signature `CogniteDataSource.Contents` and separates authentication from data fetching, exposing a table of functions you can choose from.

### Migration approach

Choose a migration approach based on the effort you want to invest and the performance improvements you need:

**Option 1: Minimal changes using ODataCDF**

For the fastest migration with minimal code changes, use the `ODataCDF` function which maintains compatibility with your existing OData URLs:

```js theme={"languages":{"custom":["/_languages/kuiper.json","../_languages/kuiper.json"]}}
let
    Source = CogniteDataSource.Contents("publicdata", "publicdata"),
    ODataCDF = Source{[Key="ODataCDF"]}[Data],
    CogniteCDMViews = ODataCDF("publicdata/models/spaces/cdf_cdm/datamodels/CogniteCore/versions/v1", "20230821"),
    CogniteTimeSeriesTable = CogniteCDMViews{[Name="CogniteTimeSeries",Signature="table"]}[Data]
in
    CogniteTimeSeriesTable
```

Make the following changes:

1. Replace `Cognite.Contents(` in the original query with the code to access the `ODataCDF` function as shown above.

2. Update the function call to `ODataCDF(` with the URL from the original query and the API version.

3. Remove `?tenantId=xxx` from your URLs if present. This was only needed for guest authentication in Azure ENtra ID.

4. Keep other OData query parameters, such as `$filter` and `$select`, unchanged.

**Option 2: Simplified data model access using ODataDataModel**

For cleaner code when working with data models, use the dedicated `ODataDataModel` function. This option gives cleaner syntax, no URL construction, direct parameters for `space`, `model`, and `version`, and the same OData protocol with improved usability.

```js theme={"languages":{"custom":["/_languages/kuiper.json","../_languages/kuiper.json"]}}
let
    Source = CogniteDataSource.Contents("publicdata", "publicdata"),
    ODataDataModel = Source{[Key="ODataDataModel"]}[Data],
    CogniteCDMViews = ODataDataModel("cdf_cdm", "CogniteCore", "v1"),
    CogniteTimeSeriesTable = CogniteCDMViews{[Name="CogniteTimeSeries",Signature="table"]}[Data]
in
    CogniteTimeSeriesTable
```

**Option 3: Better performance with GraphQL**

For improved performance while querying data models, migrate to GraphQL. This option gives better performance than OData and enables all features supported by the GraphQL service.

```js theme={"languages":{"custom":["/_languages/kuiper.json","../_languages/kuiper.json"]}}
let
    Source = CogniteDataSource.Contents("publicdata", "publicdata"),
    GraphQL = Source{[Key="GraphQL"]}[Data],
    CogniteTimeSeriesTable = GraphQL(
        "cdf_cdm",
        "CogniteCore",
        "v1",
        "query MyQuery($cursor: String) { 
            listCogniteTimeSeries(first: 1000, after: $cursor) { 
                items { 
                    space 
                    externalId 
                    createdTime 
                    lastUpdatedTime 
                    name 
                    description 
                    isStep 
                    type 
                    sourceUnit 
                } 
            } 
        }"
    )
in
    CogniteTimeSeriesTable
```

**Option 4: Maximum performance with direct REST API**

For best performance, use direct REST API calls. This option gives maximum performance, access to all Cognite API features, and full control over request parameters.

```js theme={"languages":{"custom":["/_languages/kuiper.json","../_languages/kuiper.json"]}}
let
    Source = CogniteDataSource.Contents("publicdata", "publicdata"),
    PostCDF = Source{[Key="PostCDF"]}[Data],
    Body = [
        sources = {
            [
                source = [
                    type = "view",
                    space = "cdf_cdm",
                    externalId = "CogniteTimeSeries",
                    version = "v1"
                ]
            ]
        },
        limit = 1000
    ],
    BodyText = Text.FromBinary(Json.FromValue(Body)),
    CogniteTimeSeriesTable = PostCDF("/models/instances/list", BodyText)
in
    CogniteTimeSeriesTable
```

### Migration steps

<Steps>
  <Step title="Open the report">
    Open the Report in Power BI Desktop.
  </Step>

  <Step title="Update each query">
    1. Open the Power Query editor.

    2. Select a query using the OData connector.

    3. Replace the connector code following one of the options above.

    4. Remove `tenantId` parameter if present in URLs.
  </Step>

  <Step title="Sign in">
    Sign in using your CDF organization credentials.
  </Step>

  <Step title="Update all queries">
    Update all queries in your report.
  </Step>

  <Step title="Test the changes">
    Test thoroughly before publishing.
  </Step>

  <Step title="Publish and update scheduled refreshes">
    Publish and update scheduled refreshes in the Power BI service.
  </Step>
</Steps>
