Sales Analysis with Power BI Desktop and Autonomous Database

Power BI Desktop is a business analytics service by Microsoft. It offers interactive visualizations and business intelligence capabilities with a simple interface, letting the end-users create reports and dashboards.

Oracle Autonomous Data Warehouse (ADW) is a fully managed and high-performance solution, turned and optimized for Data Warehouse workload. It means you don’t need to take more effort and resources (DBA role) to manage the database and optimize the workload.

The current article describes the process of creating a Sales Analysis with Power BI Desktop and data hosted in Oracle Autonomous Database.

CodingSight - Sales Analysis with Power BI Desktop and Autonomous Database

Prerequisites

Before we start the process, you need to make sure that you have the necessary equipment:

  • Download and install the latest version of Power BI Desktop for analytics – follow up the system requirement and instruction before installing the application.
  • Install the Instant Oracle Database Client, version 12.1.0.2 or higher on the Power BI environment.
  • Provision ADW database instance and download ADW Wallet file, then unzip the ADW wallet file to the secured folder.
  • Download the sample file and load its data into your ADW database instance.

Create an Oracle Autonomous Database Connection in Power BI Desktop

You cannot create a connection to Oracle Autonomous Database in Power BI Desktop directly. Instead, you must create a system TNS_ADMIN variable in Windows. This variable points to the secured folder with the ADW wallet file.

Press Win+R to open the Run dialog box and enter the following command:

rundll32.exe sysdm.cpl,EditEnvironmentVariables

The Environment Variables window appears immediately. Click New to create the TNS_ADMIN variable if it does not exist:

The Environment Variables window appears immediately. Click New to create the TNS_ADMIN variable if it does not exist
  • Enter the variable name: TNS_ADMIN
  • Enter the variable value: absolute the path to the secured folder where unzipped wallet file is stored
  • Click OK
Enter the variable name: TNS_ADMIN. Enter the variable value: absolute the path to the secured folder where unzipped wallet file is stored. Click OK

Now you need to reboot the computer to make sure that the system variable works. When done, open Power BI Desktop and click Get Data:

Reboot the computer to make sure that the system variable works. When done, open Power BI Desktop and click Get Data

Select Oracle Database

Select Oracle Database
  • Enter the service name. You get the ADW service name from the tsnnames.ora file in that secured folder where you store the unzipped ADW wallet file.
  • Enter the adwdemo_high service.
Enter the service name. You get the ADW service name from the tsnnames.ora file in that secured folder where you store the unzipped ADW wallet file.
Enter the adwdemo_high service.

When you connect to the data source such as SQL Server, Oracle, etc., you need to consider the Data Connectivity mode.

  • Import: The selected tables and columns are imported into Power BI Desktop. It means that both the metadata and data are imported into Power BI Desktop during the initial phase. When you create or interact with the visualization, Power BI Desktop uses imported data. You must refresh it to get the latest version from the underlying data source. This option is suitable for small datasets.
  • Direct Query: No data is imported or copied into Power BI Desktop. When you create or interact with a visualization, Power BI Desktop queries the underlying data source. Thus, you will always view the current data. This option is suitable for large datasets.

You might also be required to enter the ADW database user name and password.

In the Navigator window, choose the database schema > DEMO > filter the SALES table > SALES_ORDERS table

In the Navigator window, choose the database schema > DEMO > filter the SALES table > SALES_ORDERS table

Click Transform Data. Here, you do the transformation in the dataset imported, such as renaming, changing data type, etc.

  • If you see the ABC icon, it means the column data type is Text
  • If you see the Calendar icon, the column data type is Date or Date/Time
  • If you see the 1.2 icon, the column data type is Number
  • To rename the column, right-click on that column > Rename
  • To change the data type, right-click on that column > Change Type > select the necessary data type, e.g., Text
  • Click Close & Apply
Click Transform Data. Here, you do the transformation in the dataset imported, such as renaming, changing data type, etc.

Create the Time Series Dataset

The Time dataset is essential when you want to analyze the time series, such as Month over Month, Month to Date, Quarter over Quarter, etc. We are going to build the Time dataset from SALES_ORDERS loaded before, using the DAX function.

  • Right-click on the SALES_ORDERS dataset in Fields on the right > Rename > Sales
  • Click on the Sales dataset > New Table in the Table Format menu > enter the following DAX expression
Time = CALENDAR(MIN(Sales[Order Date]),MAX(Sales[Order Date]))

This expression creates the Calendar time based on the Order Date column of the Sales dataset. Click Enter.

This expression creates the Calendar time based on the Order Date column of the Sales dataset. Click Enter

Click on the Model tab > Drag the Order Date of Sales to the Date of Time dataset to create a relationship:

Click on the Model tab > Drag the Order Date of Sales to the Date of Time dataset to create a relationship

Create Measures in a Dataset

After creating the connection to ADW, you can create reports based on the imported datasets. Pay attention to the Data Connectivity mode used during the process of creating the connection, as both metadata and data were imported into Power BI Analytics Desktop.

Now, let us compare Revenue of Year to Date to Revenue of Last Year to Date. For that, we need to create new measures using the DAX functions in your dataset.

Total Sales

Right-click on the Sales dataset > New measure and enter the DAX expression:

Total Sales = SUM(Sales[Sales])

Total Sales YTD

Right-click on the Sales dataset > New measure. You will use the TOTALYTD DAX function and the Time dataset to calculate Total Sales from January to the current period. The DAX expression is below:

Total Sales YTD = TOTALYTD([Total Sales], 'Time'[Date].[Date])

Total Sales Last YTD

Right-click on the Sales dataset > New measure. We’ll use the CALCULATE and SAMPERIODLASTYEAR DAX functions and the Time dataset to calculate Total Sales from January to the current period. The DAX expression:

Total Sales Last YTD = CALCULATE([Total Sales YTD],SAMEPERIODLASTYEAR('Time'[Date].[Date]))
Right-click on the Sales dataset > New measure. We’ll use the CALCULATE and SAMPERIODLASTYEAR DAX functions and the Time dataset to calculate Total Sales from January to the current period

Total Orders

DAX expression:

Total Orders = DISTINCTCOUNT(Sales[Order ID])

Total Profit

DAX expression:

Total Profit = SUM(Sales[Profit])

% Sales YTD

We are going to calculate % between the Total Sales YTD and Total Sales Last YTD

DAX expression:

% Sales YTD = IF([Total Sales Last YTD]>0,(([Total Sales YTD] - [Total Sales Last YTD]) / [Total Sales Last YTD] * 100.00),0)

Build the Sales Analysis In Power BI Desktop

1. Total Sales Year to Date

The report will display the Total Sales YTD of the Current Period:

  • Chart Type: Card
  • Choose the Card visualization type in the Visualization panel
  • Drag and drop Total Sales YTD to the Add data field here
Build the Sales Analysis - Total Sales Year to Date

2. Total Sales YTD vs Total Sales Last YTD

The report displays the comparison between Total Sales YTD and Total Sales Last YTD by Year

  • Chart Type: Table chart
  • Choose the Table chart type in the Visualization panel
  • Expand the Time dataset and select Year in the hierarchy
  • Choose both Total Sales YTD and Total Sales Last YTD
Build the Sales Analysis - Total Sales YTD vs Total Sales Last YTD

Go to Format and change the text size to 18pt

Total Sales YTD vs Total Sales Last YTD

3. Profit By Customer Segment

This report will display Total Profit by Customer Segment

  • Chart Type: Donut chart
  • Title Name: Profit By Customer Segment
  • Choose Total Profit and Customer Segment
Build the Sales Analysis - Profit By Customer Segment

4. % Sales YTD change

This report will display % Sales Change (Up or Down) between Total Sales YTD and Total Sales Last YTD

  • Chart Type: Line and Stacked Bar chart
  • Choose Line and Stacked Column chart in Visualizations
  • Choose % Sales YTD, Total Sales YTD, and Year of Time datasets
Build the Sales Analysis - % Sales YTD change

5. Total Profit By Customer Segment and Product Category

This report will display Total Profit distribution by Customer Segment and Product Category

  • Chart Type: 100% Stacked Bar chart
  • Choose 100% Stacked Bar chart in Visualizations
  • Choose Customer Segment, Product Category, and Total Profit
  • Go to Format > Data Label = On
Build the Sales Analysis - Total Profit By Customer Segment and Product Category

Conclusion

Oracle Autonomous Database provides plenty of solutions to help you to leverage your performance workload. No matter if you are working with Power BI, Qlik, Tableau, or any Self-service tools for analytics, you can connect to the Oracle Autonomous Database and continue working on your datasets if they are migrated to Oracle Cloud.

This option also helps you save costs if you purchased Business Intelligence tools or application licenses. Just lift and shift your datasets to Oracle Autonomous by minimizing the operation effort of the database platform and infrastructure.

Read also

Formatting Data in Power BI Desktop Visualizations

Dung Dinh

Dung Dinh

BI Specialist, Data Modelling, working as Oracle Consultant in Oracle Cloud.

Leave a Reply

Your email address will not be published. Required fields are marked *