How to Connect External APIs to Power BI With Claude Code

Claude Code Power BI tutorial blog graphic showing how to connect external APIs, featuring Collectiv, Claude, and Power BI logos.

How to Connect External APIs to Power BI With Claude Code

Using Claude Code with Power BI can make working with external data a lot easier. Instead of manually figuring out API connections, writing Power Query transformations, and building a report from scratch, you can use Claude Code to help with the process. But what does that actually look like?

Collectiv Senior Analytics Consultant Liz Torres recently put together a walkthrough showing how she uses Claude Code to bring U.S. Census data into Power BI, transform it with Power Query, and build a report comparing patient demographics with local population data.

Let’s look at how it works.

Can You Use Claude Code to Connect External Data to Power BI?

Yes. Claude Code can help you retrieve data from external APIs, build Power Query transformations, organize data models, and create Power BI reports. Instead of manually writing every transformation or figuring out unfamiliar API structures on your own, you can give Claude Code a clear set of instructions and have it help build the solution. That doesn’t mean you should skip reviewing the work. You’ll still want to check the transformations, relationships, and calculations to make sure everything is accurate. But it can make getting started with external data a lot easier.

Watch: How to Connect External Data to Power BI With Claude Code

In this walkthrough, Liz shows how she uses Claude Code to retrieve U.S. Census data, prepare it in Power Query, and build a Power BI report that compares patient demographics with local population data. The patient information is entirely fictional, but the approach can be applied to many real-world analytics scenarios.

Why Bring External Data Into Power BI?

Your internal data can tell you a lot about your business. But sometimes you need information from outside your organization to understand the bigger picture. Think about a healthcare organization. It might know how many patients it serves, where those patients live, and their age and gender distribution. But how does that compare with the population of the surrounding community? Are certain age groups represented differently? Are there geographic areas worth looking into more closely? That’s where external data can help.

By combining internal information with publicly available U.S. Census data, you can start answering questions that wouldn’t be possible with your internal data alone. And the same idea applies beyond healthcare. Organizations can use external economic, demographic, geographic, or industry data to add context to their reporting.

Step 1: Find the Data You Need

For this walkthrough, we’re using data from the U.S. Census Bureau. If you’ve ever explored data.census.gov, you know there’s a lot of information available. Population estimates, age and sex, housing, income, and more. The challenge isn’t necessarily finding data. It’s figuring out which tables and variables contain what you actually need. Many Census tables use identifiers and coded fields that aren’t immediately obvious. Rather than spending time manually sorting through all of that, Liz uses Claude Code to help identify the relevant data. In this case, we’re looking for age and gender population information for the cities where our fictional patients live.

Step 2: Connect to the U.S. Census API

Next, we need a way to retrieve that data. The U.S. Census Bureau provides an API that allows applications to request Census data directly. You can find information about the API and request an API key at api.census.gov.

For this walkthrough, Liz makes her API key available to Claude Code so it can retrieve the data. One thing worth mentioning: When you’re working with API keys or other credentials, make sure they’re stored securely and aren’t exposed in shared files, recordings, or source code.

Step 3: Tell Claude Code What You Want to Build

This is where things get interesting. Rather than asking Claude Code to simply import Census data, Liz gives it a specific goal. She wants to compare the age and gender distribution of the fictional clinic’s patients with Census data for the cities where those patients live.

She also provides a few important instructions:

  • Use the Excel file containing the fictional patient data.
  • Retrieve the most recent appropriate Census data available.
  • Create a star schema with the patient and Census datasets.
  • Use the available Census API credentials.
  • Keep the transformation steps in Power Query so they can be reviewed
  • Build a report that makes it possible to compare the two populations.

That last part about Power Query is important. We don’t just want Claude Code to produce a finished report without knowing how the data got there. We want to be able to inspect the transformations, understand what happened, and make changes if needed.

Example Claude Code Prompt

If you’re experimenting with a similar workflow, here’s an example of how you could structure your request:

“Create a Power BI report that compares the age and gender distribution of patients in my fictional patient Excel dataset with U.S. Census population data for the cities where those patients live. Use the most recent appropriate Census data available through the Census API. Create a star schema to support the comparison, using the patient dataset and Census data as sources. Keep the data retrieval and transformation logic in Power Query so I can inspect the steps. Build report visuals that compare patient demographics with the corresponding Census demographics by age, gender, and city. Document the tables, relationships, and transformation logic so I can review the results.”

The more context you give Claude Code about what you’re trying to accomplish, the better starting point it has. *This is an illustrative prompt based on the walkthrough, rather than a verbatim copy of Liz’s original instructions.*

Step 4: Open the Report and Refresh the Data

After Claude Code finishes, we can open the Power BI report it created. One thing you’ll notice in the video is that the visuals are initially blank. That’s because the data needs to be refreshed. Once Liz refreshes the report, the visuals populate and we can start exploring the results. It’s also worth noting that the initial layout isn’t perfect. A few slicers need resizing. That’s a useful reminder that AI can help build a starting point, but you’ll still want to review and refine the finished report.

Step 5: Explore the Demographic Comparisons

Now we can see what the data tells us. The report includes several ways to compare the fictional clinic’s patient population with the surrounding Census population.

Comparing age groups

We can look at the age distribution of the patients alongside the broader population. This helps us understand whether certain age groups are represented differently in the clinic’s patient data.

Comparing gender distribution

The report also compares gender distributions. One particularly useful visual shows the difference between the percentage of patients in a demographic group and that group’s percentage of the Census population. Instead of only looking at raw counts, we can see how the two populations differ proportionally.

Looking at individual cities

There’s also a city-level view. This lets us explore how the patient population compares with Census demographics in different geographic areas. For a healthcare organization, those comparisons might help identify areas worth investigating for future outreach. Of course, demographic differences alone don’t tell the whole story. They’re a starting point for asking better questions.

Step 6: See What Claude Code Built in Power Query

This might be the most useful part of the walkthrough. After looking at the report, Liz opens Power Query to see how Claude Code prepared the Census data. And there’s quite a bit happening behind the scenes.

Census data often comes back with coded variables. Those codes need to be interpreted before the data can be used in a meaningful report. Claude Code helps work through those transformations, identify the relevant population counts, and organize the fields needed for analysis. By the end, we have a dataset with the age groups, gender information, and population values needed for our comparisons. And because the transformation steps are kept in Power Query, we can see what Claude Code did.

We can review the logic, make adjustments, and understand how the data was prepared. That’s an important part of using AI in analytics. The goal isn’t just to get an answer faster. It’s to build something you can understand, validate, and maintain.

Where Can Claude Code Help With Power BI Development?

This walkthrough focuses on Census data, but there are several ways Claude Code can support Power BI development.

Working with unfamiliar APIs

If you’re connecting to a new data source, Claude Code can help you navigate its structure and develop the logic needed to retrieve the information.

Building Power Query transformations

Instead of writing every transformation from scratch, you can use Claude Code to help generate the steps needed to clean and prepare data.

Creating data models

Claude Code can assist with organizing tables and relationships to support reporting and analysis.

Prototyping reports

When you’re exploring a new use case, Claude Code can help you get to an initial report more quickly so you can spend more time refining the analysis.

None of this removes the need for good data engineering practices. But it can reduce some of the repetitive development work.

What Should You Check Before Using AI-Generated Power BI Reports?

Just because Claude Code can help build a report doesn’t mean everything it produces is automatically ready for production. There are a few things we’d recommend checking:

  • Data accuracy: Are you pulling the correct data, reporting period, and geographic information?
  • Power Query transformations: Are the fields being interpreted and transformed correctly?
  • Data model: Do the relationships, keys, and filters work as expected?
  • Refresh behavior: Will the data continue to refresh reliably?
  • Security: Are credentials and sensitive information properly protected?
  • Report design: Are the visuals and comparisons clear enough for someone else to use?

AI can help with the development process, but you still need people who understand the data and can validate the results.

Frequently Asked Questions

Can Claude Code create Power BI reports?

Yes. Claude Code can assist with creating data models, Power Query transformations, and report components. You’ll still need to review, refresh, and validate the results.

Can Claude Code connect Power BI to external APIs?

Claude Code can help develop the queries and transformations needed to retrieve external API data for Power BI. In this walkthrough, Liz uses it to bring U.S. Census data into a Power BI report.

Does Claude Code replace Power Query?

No. Claude Code can help create transformations, but Power Query is still where you can inspect, manage, and refine the data preparation process.

Can I combine Excel data with U.S. Census data in Power BI?

Yes. You can bring both datasets into Power BI and model them for comparison. In our example, we use fictional patient data from Excel alongside Census population data.

Do I need an API key to access U.S. Census data?

The workflow in this video uses a Census API key. Requirements can vary depending on the API and endpoint, so check the Census Bureau’s documentation.

Should I trust AI-generated Power BI transformations?

You should review and test them before using them in production. Claude Code can help generate the transformations, but it’s still important to validate the underlying logic and data.

Making External Data Integration Easier With AI

One of the things we like about this example is that it shows a practical way to use AI in an existing analytics workflow. We’re not replacing Power BI or Power Query. We’re using Claude Code to help with some of the work that happens before the data is ready for analysis. Finding the right external data, working through API structures, preparing transformations, and getting everything into a usable model can take time. AI can help make that process more manageable. And when we keep the transformations visible and reviewable, we can take advantage of that assistance without giving up control over the solution.

At Collectiv, we’re exploring how tools like Claude Code can help teams work more efficiently with the data platforms they already use. Looking for help with Power BI, data integration, or practical AI implementation? Our team works with organizations to build, modernize, and improve their data and analytics environments. Connect with Collectiv

Share this:

Related Resources

Who Owns Relevance? Five Questions Every Data Leader Should Answer Before Scaling AI

AI-Ready Data Is Not Clean Data: A Smarter Way to Prepare Your Business for AI

Your Copilot Is Not Broken, It Is Guessing: The Retrieval Gap in AI

Stay Connected

Subscribe to get the latest blog posts, events, and resources from Collectiv in your inbox.

This field is for validation purposes and should be left unchanged.