DEV Community

Cover image for Connecting Power BI to SQL Databases: A Beginner's Guide
Ng'ang'a Njongo
Ng'ang'a Njongo

Posted on

Connecting Power BI to SQL Databases: A Beginner's Guide

Power BI is one of the most powerful tools for data analysis and business intelligence. It allows users to visualize their data through interactive dashboards and reports, making it easier for companies to track performance, identify trends, and make informed decisions.

While Power BI can import data from simple files like Excel or CSVs, most professional organizations store their data in SQL databases. These databases are essential for managing large volumes of structured data efficiently, ensuring data integrity, and providing a "single source of truth" for the entire company. By connecting Power BI directly to a SQL database, analysts can work with real-time data and build scalable reporting solutions.

Connecting to a Local PostgreSQL Database

PostgreSQL is a popular open-source relational database. If you have a local instance of PostgreSQL running on your machine, connecting it to Power BI is a straightforward process.

Step-by-Step Connection:

1 Open Power BI Desktop: Start by launching the application on your computer.
2 Select Get Data: On the Home ribbon, click the "Get Data" icon.
3 Choose PostgreSQL Database: From the "Get Data" window, select "PostgreSQL" from the list.

Get Data

4 Enter Server Details: Enter the Server name, in our case it's: localhost. Also specify the Database name you want to connect to.
5 Authentication: Choose the Database tab in the authentication window. Enter your PostgreSQL Username and Password.
6 Load Tables: Once connected, the Navigator window will display all available tables. You can select the ones you need and click Load.

DB Connections

Load Data

Connecting to a Cloud Database: Aiven PostgreSQL

Many companies use cloud-managed databases like Aiven for PostgreSQL to handle their production data. Cloud databases offer high availability and security but require a few extra steps to connect.

Step-by-Step Connection:

1. Login to Aiven: Login into Aiven and select create service as below:

Aiven Login

2. Postgres Configurations: Select PostgreSQL service and on the configuration page, configure below:

  • Service Tier

  • Region

  • Plan

3. Create Service: Once above configurations are done, click "Create Service"

Create Service

Obtaining Connection Details

Once you've created your PostgreSQL service on Aiven, gather the following information from your service overview:
• Host
• Port
• Database Name
• Username & Password

See example below:

Aiven Connection

The Role of SSL Certificates

Cloud connections often require SSL (Secure Sockets Layer) certificates. SSL encrypts the data moving between the database and Power BI, preventing unauthorized parties from intercepting sensitive information.

To include the certificate in Power BI:

  1. Download the ca.pem file from the Aiven console.
  2. Open Command Prompt or PowerShell as Administrator. Run the following command to add the certificate to the Root Store: certutil -addstore -f "Root" <path_to_your_ca.pem_file>
  3. In Power BI, when prompted for the connection, ensure the "Encrypt connections" option is checked.

Aiven SSL

Install SSL

  1. Get Data → PostgreSQL database
  2. Enter Aiven connection details:

Aiven Host

NB:
Advanced options → Add SSL parameters:
powerquery
let
Source = PostgreSQL.Database(
"your-service.aivencloud.com:12345",
"defaultdb",
[
CreateNavigationProperties = true,
SSLMode = "Require",
UseSSL = true
]
)
in
Source

Why SQL Skills are Vital for Power BI Analysts

While Power BI provides a user-friendly interface for connecting to data, having SQL (Structured Query Language) skills is a game-changer for any data analyst.

Data Retrieval: SQL allows you to write custom queries to pull only the specific columns and rows you need, reducing the load on Power BI and improving performance.
Data Filtering and Aggregation: Instead of bringing millions of rows into Power BI, you can use SQL to aggregate data at the database level.
Data Cleaning: SQL is efficient at handling "messy" data—renaming columns, handling null values, and formatting dates—before the data even reaches your dashboard.
Complex Logic: Some business logic is easier to write in SQL than in Power BI’s DAX language, especially when involving complex joins or window functions.

By mastering both SQL and Power BI, you become a versatile analyst capable of handling the entire data pipeline—from the raw database to the final executive dashboard.

Top comments (0)