> ## 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 REST API connector

> Use the Power BI REST API connector to fetch data with Cognite's OData services or other Cognite APIs using GET, POST, and GraphQL queries.

## Select data access method

The REST API connector provides three ways to access Cognite Data Fusion (CDF) data:

| Method                     | Best for                                                        | Performance      | Coding required   |
| -------------------------- | --------------------------------------------------------------- | ---------------- | ----------------- |
| **OData services**         | Quick exploration, simple queries, no-code users                | Baseline         | No                |
| **GraphQL**                | CDF data Models, precise field selection                        | Good             | Minimal           |
| **Direct REST (GET/POST)** | Large data sets, complex integrations, full Cognite API support | Up to 10x faster | Yes (Power Query) |

<Tip>
  Start with OData for simplicity. Use GraphQL for data models. Switch to direct REST calls when you need maximum performance or access to specific Cognite APIs.
</Tip>

<Info>
  Download the [Power BI template](/cdf/dashboards/references/rest/powerbi_rest_examples#power-bi-template) with pre-configured utility functions and helper queries to get started faster.
</Info>

<a id="set-up-a-connection-to-cognite-data-fusion-cdf" />

## 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**</span> (<span translate="no">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 organizational account.
  </Step>

  <Step title="Select the Cognite Data Fusion REST API 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 (REST API)** connector.

    <Frame>
      <img src="https://apps-cdn.cogniteapp.com/@cognite/docs-portal-images/1.0.0/images/cdf/dashboards/powerbi/update2024/REST1.png" alt="Locate the CDF REST API 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">CDF project</span>: Enter the name of the <span translate="no">CDF</span> project you're connecting to.

    * <span class="ui-element">CDF organization</span>: Enter the organization to use to sign in to <span translate="no">CDF</span>.

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

  <Step title="Authenticate with your account">
    When prompted, sign in with your 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 functions and transform data">
    Select the [function(s)](/cdf/dashboards/references/rest/powerbi_rest_functions) you want to use, and then select <span class="ui-element">Transform Data</span> 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/update2024/REST4_v1.png" alt="Selecting functions using the REST API connector in Power BI" width="80%" />
    </Frame>
  </Step>
</Steps>

<a id="set-up-a-connection-to-cognite-data-fusion-cdf" />

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

Follow these steps to connect to <span translate="no">CDF</span> from Power Query Online.

<Steps>
  <Step title="Select Cognite Data Fusion REST API">
    Select **Cognite Data Fusion (REST API)** 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/rest/online-get-data-new.png" alt="Screenshot of the get data window with Cognite Data Fusion (REST API) emphasized." width="80%" />
    </Frame>
  </Step>

  <Step title="Configure connection settings">
    In <span class="ui-element">Connection settings</span>, enter the following information:

    * <span class="ui-element">CDF project</span>: Enter the name of the <span translate="no">CDF</span> project you're connecting to.
    * <span class="ui-element">CDF organization</span>: Enter the organization to use to sign in to <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/rest/online-connection-settings-new.png" alt="Screenshot of the Cognite Data Fusion (REST API) 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/rest/online-connection-credentials-new.png" alt="Screenshot of the Cognite Data Fusion (REST API) online connection credentials." width="80%" />
    </Frame>
  </Step>

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

  <Step title="Choose function and create data connection">
    In **Choose data**, select the function you require, then select <span class="ui-element">Create</span> 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/rest/online-navigator.png" alt="Screenshot of the Power Query Online Navigator showing the available functions." width="80%" />
    </Frame>
  </Step>
</Steps>

<a id="filtering-data" />

### Filter data

Use the maximum supported page size if you make requests that support pagination via `limit` parameters in GET/POST requests, or the `first` parameter in GraphQL queries. Smaller page sizes increase API calls and can significantly impact load times. See the [Cognite API documentation](/api-reference/concepts/20230101/api-description) for the maximum supported page size for each endpoint. For <span translate="no">GraphQL</span> queries, the maximum limit is 1000 instances per page.

When using the REST API functions, you can **apply server-side filters** to reduce the initial data loaded into <span translate="no">Power BI</span>.

If you're using OData, <span translate="no">Power BI</span> can **push down** some filters to the <span translate="no">OData</span> service when using the <span translate="no">Power Query</span> editor.

For <span translate="no">GraphQL</span> queries, you can **apply filters directly in the query** to reduce the amount of data loaded into <span translate="no">Power BI</span>. You can also use <span translate="no">GraphQL</span> query variables to parameterize your queries and make them more reusable.

<a id="understanding-schema-and-type-handling" />

### About schema and type handling

This is how schema and type information is handled when retrieving data using the different functions in the connector.

<span class="ui-element">OData functions</span>

When fetching data with the `ODataCDF` or `ODataDataModel` functions:

* Tables always include type information as the OData protocol includes metadata for every property.

* Even if the result contains no data, for instance due to filtering or an empty resource, the returned table will have a defined schema with properly typed columns.

<span class="ui-element">REST and GraphQL functions</span>

When fetching data with the `GetCDF`, `PostCDF`, or `GraphQL` functions, the outcome can vary:

**Successful with data**: Returns a table with columns based on the unique properties found in all records present in the API response. Column types are initially set as `any` since the REST API doesn't provide type metadata.

**Successful but empty**: Returns an empty table with no columns, since the API response doesn't include schema information when no data is present.

**Failed request**: Throws an error, similar to OData functions.

<span class="ui-element">Best practices for REST functions</span>

Due to the variable schema behavior with REST functions, it's recommended to:

* Manually define an expected schema with column names and types when using REST functions.

* Apply type transformations to ensure consistent data types across refreshes.

* Consider using a sample query to establish a schema template, then applying that schema even when results might be empty.

You can find examples and more information about schema handling for REST and GraphQL functions in [incremental refresh with Power BI](/cdf/dashboards/references/rest/powerbi_rest_incremental_refresh).

<a id="scheduled-refresh" />

### Scheduled refresh

After publishing your report to the <span translate="no">Power BI</span> service, you must configure scheduled data refreshes to keep your data current and maintain authentication.

<Warning>
  **Token expiration**: The REST API connector uses refresh tokens that expire after 26 hours. To prevent authentication failures:

  * **Schedule at least 2 daily refreshes** in the Power BI service.
  * Refreshes must occur within 24 hours of each other to maintain the authentication token.
  * If the token expires, you must manually re-authenticate by selecting <span class="ui-element">Edit credentials</span> in the data set settings.
</Warning>

<a id="error-handling" />

### Error handling

When you're writing custom `GET` and `POST` requests, you may get errors if you provide an invalid URL or body. If you receive a `CogniteAPIError` error message, see the [Cognite API reference documentation](/api-reference/concepts/20230101/api-description) and adjust your request.
