SQLServerCentral Article

Tutorial to Create a Power BI Report Using PostgreSQL

,

Introduction

The current article will show how to create a Power BI report using PostgreSQL data.

This article is for people who need to work with PostgreSQL to create reports in Power BI, but do not have experience in PostgreSQL. If you do not have Power BI experience, you can still follow this step-by-step tutorial. The article will cover the following topics:

  • Requirements to create a Power BI report using PostgreSQL
  • PostgreSQL Installation
  • Create a table with data in PostgreSQL
  • Create a Power BI report using PostgreSQL

Let’s start the installation.

Requirements to create a Power BI report using PostgreSQL

PostgreSQL Installation

First, run the setup and press next.

Setup PostgreSQL

Secondly, select the installation directory and press Next.

Installation Directory

Thirdly, select the components to install. Select the PostgreSQL Server, the pgAmdin 4, and the command line tools. You could select the Stack builder, but we are not going to use it in this tutorial. The Stack Builder is an intuitive interface used to download and install modules.

PostgreSQL components

Also, we have the data directory which is the path where the databases will be stored. Select the directory of your preference.

PostgreSQL Data Directory

In addition, the software will ask for a password. Please do not forget your password. The superuser's name is postgres.

PostgreSQL Password

Next, write the port for your database server and press Next.

PostgreSQL port

Also, you need to define the locale used by the new database cluster. Select the locale and press Next.

Advanced Option locale in PostgreSQL

If everything is OK, you will see a Pre-Installation Summary, press Next.

PostgreSQL Pre Installation Summary

Finally, you will competition message to Finish the setup. Press the Finish button.

Completing the PostgreSQL Setup Wizard

Create a table with data in PostgreSQL

First, in the Windows menu, go to PostgreSQL and select pgAdmin. For SQL Server users, let’s say that the pgAdmin is like the SSMS for PostgreSQL.

Open the pgAdmin 4

Secondly, write the Postgres user password. This password was configured during the PostgreSQL installation.

Enter the posgres password

Thirdly, check your database. The database name by default is postgres. You could also go to Schemas and Tables and create your tables using the UI.

Create a table in PostgreSQL

However, I am not going to use the UI, to simplify the tutorial I will use the Query Tool to create tables and insert the data using SQL. To do that right-click the database, and select Query Tool.

Use the Query Tool in PostgreSQL

You can write the create sentence to create a table and you also have the button to execute the query.

CREATE a table in PostgreSQL

Create a sales table and insert 3 rows using the following T-SQL sentences and execute them.

CREATE TABLE sales (
sales_id INT PRIMARY KEY,
ItemsSold int,
salesdate date
);
INSERT INTO sales (sales_id,ItemsSold,salesdate)
VALUES(1,3,'2020-01-12');
INSERT INTO sales (sales_id,ItemsSold,salesdate)
VALUES(2,5,'2021-02-22');
INSERT INTO sales (sales_id,ItemsSold,salesdate)
VALUES(3,7,'2021-03-03');

If you use the select sentence, you will see the following data.

select * from sales;

Show the data in PostgreSQL

Finally, we are ready to go to Power BI.

Create a Power BI report using PostgreSQL

First, open Power BI Desktop and select Get data.

Create a Power BI report using PostgreSQL - Get Data

Secondly, go to Database and select PostgreSQL Database, and press Connect.

Create a Power BI report using PostgreSQL - connect to PostgreSQL

In this example, we will connect to the same server, so the Server name is the localhost. The database name is postgres. Press OK.

Create a Power BI report using PostgreSQL - Enter the PostgreSQL server name and database name

Also, select the sales table previously created using SQL and press Load.

Create a Power BI report using PostgreSQL - Select the PostgreSQL table in Power BI

After loading the data, you will be able to see the PostgreSQL Fields in Power BI.

Create a Power BI report using PostgreSQL - Fields created

Next, select the Pie Chart visual.

Create a Power BI report using PostgreSQL - Pie chart

Drag and drop the itemsSold and the salesdate to the pie chart.

Drag and drop fields to the Power BI pie chart.

Also, we will include a Card in the report.

Create a Power BI report using PostgreSQL - Working with Cards

Drag and drop the ItemsSold to the Card.

Drag and drop items sold to the cards

In order to modify the format, select the card and select the Format your Visual option. You can change the fonts size and colors there. Change the Category level.

Change visualization format in Power BI

Change the Callout value colors as well.

Change fonts and size in Power BI

Finally, go to View in the menu and select a theme from the gallery.

Select a Theme

Finally, you will have your report in Power BI.

Final report

Conclusion

Power BI allows connecting to several databases and non-relational sources. In this example, we learned how to connect to a local database in PostgreSQL.

Rate

4.5 (2)

You rated this post out of 5. Change rating

Share

Share

Rate

4.5 (2)

You rated this post out of 5. Change rating