DEV Community

Cover image for Connecting Power BI to a PostgreSQL Database (Local & Cloud-Aiven)
David
David

Posted on

Connecting Power BI to a PostgreSQL Database (Local & Cloud-Aiven)

Introduction

Power BI is a powerful business intelligence (BI) tool developed by Microsoft that allows users to analyze data and build interactive dashboards. It is widely used by organizations to transform raw data into meaningful insights for decision-making.

Most companies store their data in SQL databases such as PostgreSQL because they are efficient, reliable, and scalable. These databases allow structured storage of data in tables and support complex queries for analysis.

By connecting Power BI to a SQL database, analysts can:

  • Access real-time data
  • Perform advanced analysis
  • Build automated dashboards
  • Eliminate manual data entry

Connecting Power BI to a Local PostgreSQL Database

PostgreSQL connection screen

Step 1: Open Power BI Desktop

Launch Power BI Desktop and click Get Data from the Home tab.


Step 2: Choose PostgreSQL Database

  • Select PostgreSQL database
  • Click Connect

Step 3: Enter Connection Details

  • Server: localhost
  • Database: assignment
  • Select Import mode

Click OK
Enter PostgreSQL connection details


Power BI Get Data menu showing PostgreSQL option

Step 4: View Available Tables

Power BI will display all tables in the database.


Step 5: Load Tables

Select the following tables:

  • customers
  • products
  • sales
  • inventory

Click Load to import them.

Load image for importing


Connecting Power BI to Aiven PostgreSQL (Cloud)

Aiven connection setup

Step 1: Get Connection Details from Aiven

From your Aiven dashboard, obtain:

  • Host
  • Port
  • Database name
  • Username
  • Password

Connecting to Aiven PostgreSQL

Step 2: Connect in Power BI

  • Enter the host instead of localhost
  • Provide credentials

Installing SSL Certificate (Required for Cloud Connection)

Open certificate

Step 3: Download and Open Certificate

Aiven provides an SSL certificate (.crt) to secure the connection.


Install certificate wizard

Step 4: Install Certificate

  • Choose Local Machine
  • Click Next

Step 5: Choose Certificate Store

Select:
Trusted Root Certification Authorities

Select certificate store


Step 6: Complete Installation

Click Finish to install the certificate.

Finish certificate installation

Why SSL is Important

SSL certificates:

  • Encrypt data during transmission
  • Protect against unauthorized access
  • Ensure secure database connections

Creating Relationships in Power BI

Model view relationships

After loading the tables, go to Model View in Power BI.

Relationships Created:

  • customers.customer_id → sales.customer_id
  • products.product_id → sales.product_id
  • products.product_id → inventory.product_id

What is Data Modeling?

Data modeling is the process of defining relationships between tables so Power BI understands how data is connected.

Why Relationships Matter:

  • Enable accurate calculations
  • Allow filtering across tables
  • Prevent incorrect aggregations

Power BI Dashboard

Dashboard overview

Using the loaded data, a dashboard was created with the following visuals:

Sales Performance

  • Total Sales (Card)
  • Sales trends

Product Performance

  • Sales by product
  • Sales by category

Customer Insights

  • Sales per customer
  • Top customers

Inventory Insights

  • Stock levels per product
  • Inventory comparison

Conclusion: Why SQL is Important for Power BI

SQL is an essential skill for Power BI analysts because it allows them to:

  • Retrieve data using SELECT
  • Filter data using WHERE
  • Aggregate data using SUM, COUNT, AVG
  • Combine tables using JOIN

With SQL, analysts can prepare clean and efficient datasets before visualizing them in Power BI.


Final Thoughts

Connecting Power BI to PostgreSQL (both local and cloud) allows for powerful data analysis and real-time insights. By combining SQL knowledge with Power BI visualization capabilities, analysts can build meaningful dashboards that support better business decisions.

Top comments (0)