DEV Community

Cover image for Connecting Power BI to SQL Databases
MwendeMugambi
MwendeMugambi

Posted on

Connecting Power BI to SQL Databases

If you have taken time to go through my articles, then you will notice that I had given a defined Power BI a few weeks back. But for the sake of any newcomers, Power BI is a tool created by Microsoft to turn raw data into interactive insights. It is widely used by analysts, organizations, and decision-makers to track performance, identify trends, and generate insights in real time.
It is a data consumption and visualization tool, and that's why it is commonly connected to databases rather than static files. While Excel or CSV files may work for small datasets, modern organizations rely on structured databases to store, manage, and update large volumes of data efficiently.
SQL databases, such as PostgreSQL, are especially important in this ecosystem. They provide:

  • Structured storage for relational data
  • Efficient querying using SQL
  • Data integrity and consistency
  • Scalability for growing datasets

By connecting Power BI directly to a SQL database, companies ensure that their reports are built on reliable, up-to-date, and well-organized data.

Connecting Power BI to a Local PostgreSQL Database

Step 1: Open Power BI Desktop

An open Power BI Desktop
Launch Power BI Desktop.
Launched Power BI Desktop
On the home screen, locate the “Get Data” button in the top ribbon.

Step 2: Select PostgreSQL Database

  • Click Get Data
  • Search for or select PostgreSQL database
  • Click Connect

After pressing Get Data

Selecting PostgresSQL database

Step 3: Enter Connection Details
A dialogue box will appear prompting you to enter:

Sample dialogue bos
Server: localhost (if your database is running locally)
Database: (e.g., saleslux)
Click OK to proceed.

Step 4: Authenticate
Enter your PostgreSQL credentials:

The required PostgresSQL information
Username
Password
Choose the appropriate authentication method (typically Database authentication).

Step 5: Load Data into Power BI
Once connected, Power BI will display a Navigator window showing available tables.
For example:
customers
products
sales
inventory
Select the tables you need and click Load (or Transform Data if you want to clean them first).

Connecting Power BI to a Cloud Database (Aiven PostgreSQL)

When working with cloud-hosted databases like Aiven PostgreSQL, the process is similar like above, but it includes additional security steps.

Step 1: Obtain Connection Details from Aiven
From your Aiven dashboard, retrieve:
Host (e.g., your-db.aivencloud.com) - pg-726720-mwendemugambi8-cc78.c.aivencloud.com
Port (usually 5432)- 12155
Database name- defaultdb
Username- avnadmin
Password- **********

You can refer to the information here
These replace the “localhost” setup used in local connections.

Step 2: Download the SSL Certificate
Aiven requires secure connections using SSL.
Download the CA certificate (often named something like ca.pem) from the Aiven console.

Where to find your SSL Certificate
Why this matters:
SSL certificates encrypt the connection between Power BI and the database. This prevents sensitive data (like credentials or query results) from being intercepted during transmission.

Step 3: Configure the Connection in Power BI
Open Get Data → PostgreSQL
Enter:
Server: host:port (e.g., your-db.aivencloud.com:5432)
Database name

Sample connection details
During connection:
Enable SSL mode (if prompted)
Provide credentials

Loading Tables and Building Relationships
After connecting (locally or via cloud), Power BI imports your selected tables into the data model.

Typical Tables
customers containing customer details
products containing product catalog
sales containing transaction records
inventory containing stock levels

Creating Relationships
Power BI attempts to automatically detect relationships, but you should always verify them in the Model View.
PS: Different Power BI Relationships are covered in the Schemas article.

Relationships in PowerBI

Common relationships include:
customers.customer_id connected to sales.customer_id
products.product_id connected to sales.product_id
products.product_id connected inventory.product_id

Importance of Relationships
Relationships define how data flows between tables.
For example:

When you filter by a specific customer, Power BI uses the relationship to show only that customer’s sales
When analyzing product performance, sales data is grouped correctly by product
Without proper relationships:

  • Data may be duplicated
  • Aggregations may be incorrect
  • Visuals may show misleading results

Why SQL Skills Matter for Power BI Analysts

As we end this article, it is important we all understand why understanding SQL is important for all analysts. While Power BI provides powerful visualization tools, SQL remains a foundational skill for any serious analyst.

SQL allows you to:

  • Retrieve data efficiently using SELECT statements
  • Filter datasets using WHERE clauses
  • Aggregate data using functions like SUM, COUNT, and AVG
  • Join multiple tables to create meaningful datasets
  • Preprocess data before it reaches Power BI In practice, the most effective Power BI workflows involve: Preparing and shaping data in SQL Visualizing and analyzing it in Power BI

This division of work ensures that dashboards are not only visually appealing, but also accurate, scalable, and high performing.

Thank you for passing by and I hope connecting Power BI to SQL is a bit easier especially after going through this article.

Top comments (0)