Power BI Lesson 7 – Getting Data from Databases | Dataplexa
Beginner Level · Lesson 7

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.

File-based workflow
1. Database updates with new orders
2. Someone manually exports to CSV
3. Someone emails it to you
4. You replace the old file manually
5. You refresh Power BI
Slow, error-prone, dependent on humans
Direct database workflow
1. Database updates with new orders
2. You click Refresh in Power BI
Fast, accurate, no manual steps

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.

📥
Import Mode
Power BI copies the data from the database into its own in-memory storage inside the .pbix file. Queries run against the local copy — not the live database. The data is as fresh as the last time you clicked Refresh.
+Fastest report performance — all data is local
+Works offline — no database connection needed to view
+Full DAX and Power Query support
-Data is only as fresh as last refresh
-.pbix file size grows with data volume
-1 GB data limit per dataset in Power BI Service (free)
Best for: most reports — especially anything under 1 GB
DirectQuery Mode
Power BI does not copy the data. Every time you interact with a visual — click a slicer, change a filter — Power BI sends a live SQL query to the database and the database returns results in real time. The data is always current.
+Always shows live, real-time data
+No data size limits — connects to billion-row tables
+Small .pbix file — no data stored locally
-Slower — every interaction hits the database
-Requires a live database connection at all times
-Limited DAX functions — many Power Query transforms blocked
Best for: very large datasets or real-time operational dashboards

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.

1
Home → Get Data → SQL Server database Click Home → Get Data and type "SQL" in the search box. Select SQL Server database and click Connect.
2
Enter the Server and Database names A dialog appears asking for two fields. Server is the address of the SQL Server machine — for example 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.
3
Choose Import or DirectQuery Below the server and database fields is a Data Connectivity mode selector. Choose Import for most reports. Click OK.
4
Authenticate with credentials A credential dialog appears. Choose from three methods — Windows uses your current Windows login (common in corporate networks), Database uses a SQL username and password, and Microsoft Account is used for Azure SQL connected to your Azure AD.
5
Select tables in the Navigator After authenticating, the Navigator lists all tables and views in the database. Tick the ones you need. Use the preview to confirm the data looks correct. Click Transform Data to open Power Query, or Load to import directly.
SQL Server Connection Dialog
SQL Server database
Server *
SQLSRV01\PRODUCTION
Database (optional)
SalesDB
Data Connectivity mode
+ Advanced options
OK
Cancel

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.

Navigator — SQLSRV01 · SalesDB
TABLES
🗃️ Orders
🗃️ Customers
🗃️ Products
VIEWS
👁️ vw_SalesSummary
👁️ vw_TopCustomers
Preview — Orders
OrderID OrderDate CustomerID Amount Status
30012024-01-05C101$1,200Shipped
30022024-01-07C102$350Delivered
30032024-01-09C101$85Processing
30042024-01-12C103$1,200Shipped
Load
Transform Data
Cancel
🗃️ Tables
Raw storage tables — every row of data in its original form. Loading a raw table gives you the most flexibility to transform and model in Power BI. This is usually the right choice when you want to build your own data model.
👁️ Views
Pre-built SQL queries saved in the database. A view called vw_SalesSummary might already join three tables and calculate totals for you. Loading a well-designed view saves Power Query work but gives you less control over the underlying data.

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'
What this query loads into Power BI
OrderID OrderDate Amount Status CustomerName Region ProductName Category
30012024-01-05$1,200ShippedAlice BrownNorthLaptop ProElectronics
30022024-01-07$350DeliveredBob SinghSouthMonitor 27"Electronics
30032024-01-09$85ProcessingAlice BrownNorthKeyboardAccessories
Cancelled orders excluded · 2024 data only · Pre-joined across 3 tables — no relationships needed in Power BI for this query

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
Desktop credentials vs Service credentials
Desktop credentials
Stored locally — used when refreshing in Power BI Desktop only
Service credentials
Must be set separately in Power BI Service after publishing — not transferred with the .pbix file
Password changes
If a database password changes, update it in both Desktop and Service or all scheduled refreshes will fail

Common Database Connection Errors and Fixes

Cannot connect to server — check the server name is correct
The server address is wrong, the server is offline, or your machine cannot reach it over the network. Very common on laptops that are off the corporate VPN.
Fix: Confirm the exact server name with your DBA. If working remotely, connect to your VPN first. Try pinging the server name from Command Prompt to test network access.
Login failed for user
The username or password is wrong, the account does not have access to this database, or your Windows account lacks the necessary database role.
Fix: Double-check credentials. If using Windows auth, confirm with your DBA that your Windows account has been granted access to the specific database — not just the server.
Unable to connect (MySQL or PostgreSQL)
MySQL and PostgreSQL connections require an additional driver installed separately from Power BI. Without it, the connector cannot function at all.
Fix: For MySQL, install the MySQL Connector/NET driver from the MySQL website. For PostgreSQL, install the Npgsql driver. Restart Power BI Desktop after installing.
This connector requires one or more additional components (Oracle)
Oracle connections require the Oracle Data Access Client (ODAC) to be installed. The 32-bit vs 64-bit version must match your Power BI Desktop installation.
Fix: Download the correct ODAC version from Oracle's website. Ensure the bitness (32-bit or 64-bit) matches your Power BI Desktop installation exactly.

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.