Power BI Course
Getting Data from Databases
Files are a great starting point, but in most professional environments the real data lives inside a database — and connecting Power BI directly to a database instead of exporting files first gives you fresher data, less manual work, and far more control over exactly what gets loaded.
Why Connect to a Database Instead of a File?
When someone exports a database to Excel or CSV and hands you the file, you are already working with data that is hours or days old. Every time the database changes, someone has to remember to re-export. Connecting Power BI directly to the database removes the middleman entirely.
Which Databases Power BI Supports
Power BI has dedicated connectors for dozens of database systems. These are the ones you are most likely to encounter in real-world work.
| Database | Connector Name in Power BI | Typical Use |
|---|---|---|
| SQL Server | SQL Server database | Most common in corporate Microsoft environments |
| MySQL | MySQL database | Web applications, ecommerce platforms, open source systems |
| PostgreSQL | PostgreSQL database | Analytics teams, data engineering, SaaS products |
| Oracle | Oracle database | Large enterprise ERP systems (SAP, Oracle EBS) |
| Azure SQL | Azure SQL Database | Cloud-hosted SQL Server — very common in modern teams |
| Access | Access database | Small business and legacy systems using .accdb files |
Import Mode vs DirectQuery Mode
Before you connect to any database you need to make a fundamental decision about how Power BI stores and retrieves the data. There are two modes — Import and DirectQuery — and the choice affects performance, data freshness, and file size for the entire life of the report.
Teacher's Note: When you are learning or building reports on datasets that fit comfortably in memory, always choose Import mode. DirectQuery looks attractive because it sounds "live" but it creates constraints throughout the entire report — many DAX functions simply do not work in DirectQuery mode, and every slicer click becomes a round-trip to a server. The vast majority of professional Power BI reports use Import mode with scheduled refreshes.
Connecting to SQL Server — Step by Step
SQL Server is the most common database in Microsoft-heavy organisations. The steps below apply to both on-premises SQL Server and Azure SQL Database — the only difference is the server address format.
LAPTOP\SQLEXPRESS for a local instance or myserver.database.windows.net for Azure SQL. Database is optional — if you leave it blank, Power BI lists all databases you have access to. Expand Advanced options to paste in a custom SQL statement if needed.
The Three Authentication Methods
Authentication is the step where you prove to the database that you are allowed to access it. Power BI stores credentials per data source — you only need to enter them once, and Power BI remembers them for future refreshes.
| Method | When to use it | What you need |
|---|---|---|
| Windows | Connecting to an on-premises SQL Server inside your corporate network | Your Windows account must already have database permissions granted by IT |
| Database | Connecting with a dedicated SQL login — common with MySQL, PostgreSQL, and some SQL Server setups | A SQL username and password provided by your database administrator |
| Microsoft Account | Connecting to Azure SQL Database or other cloud Microsoft data services | Your Microsoft 365 or Azure Active Directory account with appropriate database permissions |
The Navigator — Tables vs Views
After authenticating, the Navigator shows every object in the database you have access to. Databases typically contain both tables and views — and knowing the difference changes which ones you should load.
| OrderID | OrderDate | CustomerID | Amount | Status |
|---|---|---|---|---|
| 3001 | 2024-01-05 | C101 | $1,200 | Shipped |
| 3002 | 2024-01-07 | C102 | $350 | Delivered |
| 3003 | 2024-01-09 | C101 | $85 | Processing |
| 3004 | 2024-01-12 | C103 | $1,200 | Shipped |
Writing a Custom SQL Query
Instead of loading entire tables, you can write a SQL SELECT statement inside Power BI to load exactly the rows and columns you need. This reduces the volume of data imported and can dramatically speed up load times on large databases. To use it, expand Advanced options in the connection dialog and paste your query into the SQL statement box.
-- Load only 2024 orders with the columns we actually need
-- Paste this into the Advanced options > SQL statement box
SELECT
o.OrderID,
o.OrderDate,
o.Amount,
o.Status,
c.CustomerName,
c.Region,
p.ProductName,
p.Category
FROM
Orders o
INNER JOIN Customers c ON o.CustomerID = c.CustomerID
INNER JOIN Products p ON o.ProductID = p.ProductID
WHERE
o.OrderDate >= '2024-01-01'
AND o.Status != 'Cancelled'
| OrderID | OrderDate | Amount | Status | CustomerName | Region | ProductName | Category |
|---|---|---|---|---|---|---|---|
| 3001 | 2024-01-05 | $1,200 | Shipped | Alice Brown | North | Laptop Pro | Electronics |
| 3002 | 2024-01-07 | $350 | Delivered | Bob Singh | South | Monitor 27" | Electronics |
| 3003 | 2024-01-09 | $85 | Processing | Alice Brown | North | Keyboard | Accessories |
Managing Database Credentials
Power BI stores credentials per data source so you do not have to re-enter them on every refresh. But sometimes you need to update them — for example when a password changes or when you want to connect with a different account.
To view or update stored credentials:
1. Home → Transform Data → Data Source Settings
2. Click the data source whose credentials you want to change
3. Click "Edit Permissions"
4. Click "Edit" next to the Credentials section
5. Enter the new username / password → click Save
To delete stored credentials:
→ Data Source Settings → select source → "Clear Permissions"
→ Power BI will prompt for credentials again on next refresh
Important: Desktop credentials are local to your machine.
If you publish to Power BI Service, enter credentials separately:
Workspace → Dataset Settings → Gateway and Cloud Connections
Common Database Connection Errors and Fixes
Teacher's Note: Before you ask your database administrator for credentials, know exactly what you need to tell them: the name of the database, which tables or views you need to read, and whether you need write access (you almost never do from Power BI). Asking for "read-only access to the Orders, Customers, and Products tables in SalesDB" will get a much faster response than asking for "database access."
Practice
Practice 1 of 3
In Import mode, Power BI ___ a copy of the data into its own in-memory storage. In DirectQuery mode every visual interaction sends a live query to the database.
Practice 2 of 3
To paste a custom SQL SELECT statement in the SQL Server connection dialog, you must expand the ___ options section at the bottom of the dialog.
Practice 3 of 3
A database ___ is a pre-built SQL query saved inside the database — it appears like a table in the Navigator but the database has already handled joining and filtering for you.
Lesson Quiz
Quiz 1 of 3
You built a Power BI report in DirectQuery mode connected to a 500 million row SQL Server table. Every slicer click takes 30 seconds to update. What is the most likely cause?
Quiz 2 of 3
A colleague publishes a Power BI report to the Service and scheduled refresh fails with a credentials error, even though the report refreshes fine in Desktop. What is the correct fix?
Quiz 3 of 3
You try to connect Power BI to a MySQL database and receive the error "This connector requires one or more additional components." What is the correct action?
Next up — Lesson 8 covers Data Source Settings in depth — how to manage all your connections in one place, update credentials, change source paths, and handle the privacy level settings that block queries when combining data from multiple sources.