How to import YouTube Analytics data into Power BI

In this guide, I will show how to use Python and APIs to connect to data sources that Power BI doesn’t support with built-in connectors. I wanted to build a Power BI dashboard for our YouTube channel to track views and other activity, so I connected to the YouTube Analytics API with a Python script and pulled the data into my Power BI model. Normally, I could export data manually from YouTube Studio, but that takes time and needs to be repeated each time I want updated results. This approach also avoids relying on spreadsheets in Google Drive or OneDrive as intermediate storage.

Prerequisites

  1. YouTube account with your own channel.
  2. Google Cloud account (for the same email id as your YouTube account).

Step 1: Enable YouTube APIs in Google Cloud

  1. Go to the Google Cloud Console.
  2. Log in with the same Google account that owns your YouTube channel.
  3. At the top, click Select a project → New Project, give it a name (e.g., YouTube Analytics Power BI), and create it.
  4. With your project selected, open the Navigation Menu → APIs & Services → Library.
  5. Search for and enable the following APIs: YouTube Data API v3, YouTube Analytics API. Once enabled, you’ll see them listed under APIs & Services → Enabled APIs & services.

Step 2: Download JSON token secret file

  1. Still in Google Cloud Console, go to APIs & Services → Credentials.
  2. Click Create Credentials → OAuth client ID.
  3. Generate a secret file and download the JSON token.

This token is a piece of that proves you have have permission to access the application, so please store it securely.

Step 3: Install the required Python libraries/packages:

Open Command Prompt or Terminal, and install these libraries/packages:

pip install google-auth google-auth-oauthlib google-api-python-client pandas
  • google-auth knows how to handle your credentials.
  • google-auth-oauthlib gets those credentials for the first time via a browser flow.
  • google-api-python-client uses the credentials to actually call Google APIs and fetch data.
  • pandas is our wrangling tool needed to turn the raw API response into a table that Power BI can display.

Step 4: Prepare your Python script.

  1. Take the code below and change the location of secret file (after CLIENT_SECRET_FILE) to where you saved in in step 2.
  2. Update your parameters (after youtube_analytics.reports().query). For a full list of required and optional parameters, click here.
  3. Update your metrics. For a full list of metrics, click here.
  4. Update your dimensions. For a full list of dimensions, click here.
import os
import pandas as pd
from google.oauth2.credentials import Credentials
from google_auth_oauthlib.flow import InstalledAppFlow
from googleapiclient.discovery import build

SCOPES = ["https://www.googleapis.com/auth/yt-analytics.readonly",
          "https://www.googleapis.com/auth/youtube.readonly"]
CLIENT_SECRET_FILE = r"C:\Users\OlegSklyarsky\Desktop\Portfolio\youtube_ko\API\client_secret_ko.json"
TOKEN_FILE = "token.json"

def authenticate_google():
    creds = None
    if os.path.exists(TOKEN_FILE):
        creds = Credentials.from_authorized_user_file(TOKEN_FILE, SCOPES)
    if not creds or not creds.valid:
        flow = InstalledAppFlow.from_client_secrets_file(CLIENT_SECRET_FILE, SCOPES)
        creds = flow.run_local_server(port=0)
        with open(TOKEN_FILE, "w") as token:
            token.write(creds.to_json())
    return creds

creds = authenticate_google()
youtube_analytics = build("youtubeAnalytics", "v2", credentials=creds)

request = youtube_analytics.reports().query(
    ids="channel==MINE",
    startDate="2025-01-01",
    endDate="2025-08-18",
    metrics="views,likes",
    dimensions="video,day"
)
response = request.execute()

cols = [col["name"] for col in response["columnHeaders"]]
rows = response.get("rows", [])
df = pd.DataFrame(rows, columns=cols)

dataset = df

Step 5: Import data into your Power BI data model

  1. In Power BI Desktop, go to Get Data → Python Script, and click Connect.
  2. Paste your finished code from step 4, and click Ok.
  3. A browser window from Google will pop up several times, asking you to allow the authentication. Click yes for each one and the data should be loaded into your data model.

Conclusion

Using Python and the YouTube Analytics API opens up a lot of flexibility for Power BI users. You are no longer limited to manual exports from YouTube Studio, and you can tailor exactly which metrics and dimensions you want to track. While this tutorial is focused on the YouTube Analytic API, you can use a similar approach for many other data sources without native Power BI connectors. If you’re comfortable experimenting with APIs, you’ll find it’s a powerful way to extend what Power BI can do.