Connect Power BI to SQL Server

Let us see the step-by-step approach to connecting Power BI to SQL Server Database. In addition, how to use Queries against the data present in Tables with an example.

Step by Step Approach to Connect Power BI to SQL Server

If you haven’t started the Desktop yet, Double click on the desktop to open it. Once it is open, it looks like the below screenshot. Please click on the Get Data hyperlink.

Select Get Data Option 1

On the visualization page, click the Get Data option under the Home tab and select the SQL Server, as shown below. Or select More options.

Use Get Data tab to Connect Power BI to SQL Server 2

We are selecting More options to show you the following window. Use this window to select your desired Data source. Here, we are discussing how to Connect Power BI to SQL Server. So, let me choose the SQL Server Database Option.

Get Data window 3

Connect Power BI to SQL Server Options

The following is the list of available fields to fill in to connect the desktop to the Database.

  • Server: Please provide the Instance name. If you installed Server with the default instance, the instance name is the computer name or localhost.
  • Database: This is optional. If you want to use a custom query, then it is required.
  • Data Connectivity Mode: Please select whether you want to import or Direct query.
Select Import under Data Connectivity Mode

Clicking the Advanced option shows you the advanced properties.

Advanced Options to Connect Power BI to SQL Server 5

You can write your own query to extract data from the specified Database. To do this, write your query inside the SQL Statement box.

Provide server name, Database, and Query 15

The custom Query that we used in the above Connect Power BI to SQL Server screenshot is:

SELECT Geo.EnglishCountryRegionName AS Country, 
       Geo.StateProvinceName AS State, 
       SUM(Fact.SalesAmount) AS Sales, 
       SUM(Fact.TaxAmt) AS Tax, 
       COUNT(Fact.OrderQuantity) AS Orders
FROM FactResellerSales AS Fact
  INNER JOIN
     DimSalesTerritory ON 
        Fact.SalesTerritoryKey = DimSalesTerritory.SalesTerritoryKey 
  INNER JOIN
     DimGeography AS Geo ON 
        DimSalesTerritory.SalesTerritoryKey = Geo.SalesTerritoryKey
GROUP BY Geo.EnglishCountryRegionName, Geo.StateProvinceName
HAVING COUNT(Fact.OrderQuantity) > 60000

While Connecting Power BI to SQL Server, click Load if you want to use this data. Let me click the cancel button because I want to select multiple tables.

View Table Data 16

NOTE: Don’t worry about the Query. Just understand the procedure. However, If you want to learn, please refer to our SQL Server Tutorial.

Let me use the local instance and click OK.

Click OK to close the window 6

We are using the current local Windows credentials for this Connect Power BI to SQL Server demo. If you don’t have permission to access the Server, use another person’s Windows credentials by selecting Use alternative credentials.

Use current windows credentials to connect 7

In real-time, we only use Database credentials. For this, select the database and enter the username and password provided by the Admin person.

For now, I am using the current Windows credentials.

Select the SQL Server Database to Connect to Power BI 8

Load or Select Tables

Under the Display options, it lists out the Databases available for that Instance. In this example, We are selecting the AdventureWorksDW2017 database.

You can download this database from Microsoft’s official Download Center or GitHub for free.

Connect Power BI to SQL Server Adventure Works DW  9

Expanding the Database folder displays the available Tables and Views. Selecting the table shows the Data Preview.

View and Select Tables inside that Database 10

From the below Connect Power BI to SQL Server screenshot, you can see that we are selecting the required tables. If you are confused about selecting tables, choose one Measure table (Orders or Sales) and click the Select Related Tables button.

  • Load: This will load data from selected tables to Power BI. As I know the data is clean, let me click the Load button.
  • Edit: Click this button to alter the columns or to cleanse the data
Connect Power BI to SQL Server and checkmark tables 11

Please wait until the load is complete

Wait until Loading Tables completes 2

You can see the Tables we selected from the database under the Fields section.

View connected SQL Server Tables inside the Power BI Desktop fields section 13

Expand any table to see the columns (fields) inside that table.

Expand any Table to View its columns 14

TIP: This is the Dataset we will use in most of the Power BI tutorials.