DEV Community

Cover image for Connecting Power BI to SQL Databases: A Step-by-Step Guide
Macphalen Oduor
Macphalen Oduor

Posted on

Connecting Power BI to SQL Databases: A Step-by-Step Guide

Introduction to Power BI and SQL Databases

Power BI is Microsoft’s leading business intelligence tool, designed to transform raw data into interactive visualizations and actionable insights.

  • It is widely used for data analysis, reporting, and dashboard creation, enabling businesses to make data-driven decisions.

SQL databases, such as PostgreSQL, are essential for storing and managing large volumes of structured data.

  • They support complex queries, transactions, and relationships, making them ideal for analytical workloads.

  • Connecting Power BI to SQL databases allows analysts to directly access, transform, and visualize data, ensuring reports are always up-to-date and accurate.


Connecting Power BI to a Local PostgreSQL Database

Step 1: Open Power BI Desktop and Select Get Data

  • Launch Power BI Desktop.
  • Click on Get Data in the Home ribbon.
  • Select PostgreSQL database from the list of data sources.

Getting Data from Postgresql database

Fig : Getting Data from Postgresql database

Step 2: Enter Connection Details

  • In the PostgreSQL database dialog, enter the server name (e.g., localhost).
  • Specify the database name you want to connect to.
  • Provide your username and password.
  • Click OK to proceed.

Server & Database Name Entry

Fig: Server & Database Name Entry

Username & Password Entry

Fig: Username & Password Entry

Step 3: Load Tables into Power BI

  • The Navigator window will display all available tables in your database.
  • Select the tables you want to import (e.g., customers, products, sales, inventory).
  • Click Load to import the data into Power BI.

Load Tables into Power BI

Fig: Loading Tables into Power BI


Connecting Power BI to a Cloud Database: Aiven PostgreSQL

Step 1: Obtain Connection Details from Aiven

  • Log in to your Aiven Console.
  • Navigate to your PostgreSQL service and find the Overview tab.
  • Note down the host, port, database name, username, and password.

Aiven.io Postgresql Service Credentials

Fig: Aiven.io Postgresql Service Credentials

Step 2: Download the SSL Certificate

  • Aiven requires SSL for secure connections.
  • Download the CA certificate from the Aiven Console.
  • Save the certificate to a known location on your computer.

Step 3: Connect Power BI to Aiven PostgreSQL

  • In Power BI, select Get Data > PostgreSQL database.
  • Enter the Aiven host, port, database name, username, and password.
  • In the advanced options, set SSL mode to Require.
  • Browse and select the downloaded CA certificate.
  • Click OK to establish the connection.

Connecting Aiven Postgresql Service to PowerBI

Fig: Connecting Aiven Postgresql Service to PowerBI

Aiven Postgresql Service Username & Password Entry

Fig: Aiven Postgresql Service Username & Password Entry

Why SSL?
SSL certificates encrypt data transmitted between Power BI and the database, ensuring security and compliance with best practices.


Loading Tables and Creating Relationships in Power BI

Loading Tables

  • After connecting, Power BI will display all available tables.
  • Select the relevant tables (e.g., customers, products, sales, inventory) and click Load.

Loading Tables from Aiven Postgresql Service into Power BI

Fig: Loading Tables from Aiven Postgresql Service into Power BI

Create Relationships

  • Go to the Model view in Power BI.
  • Drag and drop fields to create relationships between tables (e.g., customer_id in customers to customer_id in sales).
  • Power BI supports autodetect for relationships, but you can also manually define cardinality (one-to-many, many-to-one, etc.) and cross-filter direction.

Relation of Tables from the Model View in Power BI

Fig: Relation of Tables from the Model View in Power BI

Data Modeling Basics:
Relationships define how tables interact, enabling accurate analysis and visualization. Proper modeling ensures filters and aggregations work as intended.


The Importance of SQL Skills

  • Data Retrieval: SQL allows analysts to write efficient queries to extract only the data needed, reducing load times and improving performance.

  • Filtering and Aggregation: SQL skills enable complex filtering, grouping, and aggregation, which are essential for preparing data before visualization.

  • Data Preparation: SQL is often used to clean, transform, and structure data in the database, making it ready for analysis in Power BI.

  • Collaboration: Understanding SQL helps analysts communicate effectively with database administrators and data engineers, ensuring smooth data pipelines


Conclusion

Connecting Power BI to SQL databases—whether local or cloud-based—unlocks powerful analytical capabilities.

By following the steps outlined above, you can seamlessly integrate your data sources, model relationships, and build insightful dashboards.

Moreover, developing SQL skills will significantly enhance your ability to retrieve, prepare, and analyze data, making you a more effective Data Professional.

Top comments (0)