Introduction: Power BI and the Role of SQL Databases
Power BI is a tool from Microsoft that turns raw data into interactive dashboards and reports. You know those beautiful charts and graphs that managers love? Power BI makes them. But here’s the thing – Power BI on its own doesn’t store data. It needs to connect to something that does store data. That’s where databases come in.
A database is just an organised collection of information. Think of it like a giant, super‑fast Excel file that many people can use at the same time. Databases are divided into two main types:
- SQL databases (also called relational databases) – like PostgreSQL and MySQL – use tables with rows and columns, and you talk to them using the SQL language."
- NoSQL databases (like MongoDB) – they store data in other formats like JSON documents.
Connecting Power BI to a local PostgreSQL database
When we say a local database, we simply mean the database is installed and running on your own computer – not on a server somewhere else.
What you need before you start
- Power BI Desktop – free download from Microsoft.
- PostgreSQL installed and running on your machine.
- A database with some tables already created – for example, a simple sales database with tables like customers, products, sales, and inventory.
- The PostgreSQL connection driver – when you first try to connect from Power BI, it will usually detect that the driver is missing and offer to download it for you. Just follow the prompts and say Yes or Install.
Step-by-step to connecting Power BI to a locally hosted Database
Step 1. Open Power BI Desktop. You’ll see a blank canvas with a ribbon at the top.
Step 2. On the Home ribbon, click Get Data (it’s on the left). A dropdown appears – choose More… if you don’t see PostgreSQL right away.
Step 3. In the search box, type “PostgreSQL”. Select PostgreSQL Database and click Connect.
Step 4. A small window asks for two things:
-
Server: type
localhost(that’s the special name your computer uses for itself). - Database: type the name of your database that contains the data. If you’re not sure, check in pgAdmin – right‑click on the database name.
Step 5. You can leave Data Connectivity mode as Import . Click OK.
Step 6. Power BI will ask for your PostgreSQL username and password.
- Username is usually
postgres. - Password is whatever you set when you installed PostgreSQL. Choose Database as the authentication method, then click Connect.
Step 7. After a few seconds, the Navigator window appears. It shows all the schemas and tables in your database. Select the tables you wish to work on and load the data.
Step 8. You have two buttons at the bottom: Load and Transform Data.
- Load brings the tables straight into Power BI.
- Transform Data opens the Power Query Editor where you can clean or reshape the data first.
Step 9. Once the cleaning is done you can create a relationship between the tables. Open the model view and inspect the relationship between the tables.
Connecting Power BI to a cloud PostgreSQL database (Aiven)
In the real world, databases are rarely on your laptop. They live in the cloud – AWS, Google Cloud, or a service like Aiven. Connecting to a cloud database is similar to local, but with one extra step: SSL certificates.
In a nutshell, what is SSL certificates?
Think of it this way – when you share data across the internet, you don't want some random person snooping on your passwords or your sales numbers. SSL is just a technology that encrypts (secures) everything so only you and the database can read it. Cloud providers like Aiven won't even let you connect without an SSL certificate. It's a small file you download and install on your computer – it's like a digital ID badge.
Step 1. Download and install the certificate from Aiven
- Log into your Aiven and go to your PostgreSQL service.
- On the Overview tab, scroll down to Connection Information.
- Click Download CA Certificate. You’ll get a file named
ca.pem. - Rename it file from
ca.pemtoca.crt. - Double‑click the
ca.crtfile. A window pops up – click Install Certificate.
- Choose Local Machine → Next.
- Select Place all certificates in the following store → Browse.
- Choose Trusted Root Certification Authorities → OK → Next → Finish.
Step 2. Get your connection details
Still in the Aiven Overview page, copy these values:
-
Host (looks like
pg-1a2b3c4d-aivencloud.com) -
Port (a five‑digit number, e.g.,
12345) -
Database name (often
defaultdb) -
Username (usually
avnadmin) - Password (the one you set or was generated)
Step 3. Connect from Power BI
- In Power BI, click Get Data → PostgreSQL Database (same as the local host connection).
- In the Server field, combine the host and port like this:
pg-1a2b3c4d-aivencloud.com:12345
Enter the Database name (e.g.,
defaultdb).Click OK. Enter your Aiven username and password.
- The Navigator appears – same as before. Select your tables and click Load or Transform Data.
Loading tables and building relationships
Once your tables are loaded (either from local or cloud), you need to tell Power BI how they relate to each other.
The model view Click the Model icon on the left sidebar – it looks like three connected boxes. You’ll see your four tables floating.
Power BI sometimes guesses relationships automatically. But here we are going to;
Create these relationships (drag and drop):
- customers (
customer_id) → sales (customer_id) → One‑to‑Many - products (
product_id) → sales (product_id) → One‑to‑Many - products (
product_id) → inventory (product_id) → One‑to‑One
Now when you build a chart, you can drag product_name from products and total_amount from sales onto the same visual – Power BI automatically joins them.
Without these relationships, filters won't work correctly.
What is data modeling?
Data modeling is basically how you decide your tables relate to each other. You can think of it as setting up a blueprint for your data. In Power BI, this is what makes everything work together — when you click on a chart, the rest of the report updates because those relationships are already defined.
Why Relationships Matter
Relationships are what make your data useful. Without them, your tables just sit there as separate pieces of information.
For example, a sales report won’t be able to show the customer’s name, filtering by product category won’t affect your sales numbers, and in some cases, you might even end up double-counting values.
That’s how wrong insights happen — not because the data is bad, but because the connections aren’t set properly.
Types of relationships
| Type | What it means | Example |
|---|---|---|
| One-to-Many | One record in Table A links to many in Table B | One customer, many sales |
| One-to-One | One record links to exactly one other | One product, one inventory record |
| Many-to-Many | Many records on both sides (use carefully) | Multiple products in multiple orders |
Bottom line: Power BI is the kitchen. SQL is the prep cook who chops and cleans the ingredients first. Do the heavy lifting in SQL, and your dashboards will be faster and simpler.
Why SQL skills still matter
You might be thinking: "If Power BI already has drag-and-drop features, why do I still need SQL?"
The simple answer is this: Power BI is great at showing data, but SQL is better at preparing data.
Lets see some situations where SQL will be useful.
1. Loading Only What You Need
Instead of importing entire tables, you can write a SQL query in the Advanced Options when connecting.
SELECT
c.customer_id,
c.first_name,
SUM(s.total_amount) AS total_spent
FROM customers c
JOIN sales s ON c.customer_id = s.customer_id
GROUP BY c.customer_id, c.first_name;
Here, Power BI only loads a summarized dataset — which is much faster.
2. Filter at the Source
Filtering data in SQL happens before the data is even sent to Power BI.
SELECT *
FROM sales
WHERE sale_date >= '2024-01-01';
This reduces the size of the dataset and improves refresh performance.
3. Use Advanced SQL Features
Some operations are easier in SQL than in Power BI.
For example, functions like RANK() or LAG() are straightforward in SQL but can get complicated in DAX.
4. Cleaning your Data Prior
It’s always better to fix data issues at the source.
SELECT
customer_id,
UPPER(TRIM(first_name)) AS first_name,
COALESCE(email, 'no-email@example.com') AS email
FROM customers
WHERE customer_id IS NOT NULL;
This helps you avoid unnecessary cleaning steps inside Power BI.
Conclusion
We walked through connecting PostgreSQL to Power BI – whether it's on your own laptop or up in the cloud with something like Aiven.
What surprised me is that the connection part is actually the easiest step. The real work starts after that: loading the right tables, cleaning stuff up, getting the relationships right. If you skip that part, your charts will look weird and you'll be chasing problems forever.
I was working with a pretty small dataset – just a few tables, nothing crazy. But even then, I could see the pattern. It's not about which tool you use. It's about whether you bothered to prepare your data properly before dragging things onto the canvas.
Get the structure right, and Power BI feels almost too easy. Get it wrong, and you'll spend hours fixing filters and wondering why your totals don't match. I've been there. It's not fun.
So yeah – take the extra time to model things correctly. You'll have fun and enjoy every bit.


















Top comments (0)