SQLPowerBI en
SQLPowerBI en
• Proficient in using popular data analysis tools: SQL, Power Bi. and have the
mindset to be able to use other tools easily.
• Master the process of searching and analyzing data to find insights to serve the
business's strategic decision making.
• Master the foundation to be able to advance quickly and further in the data
analysis industry with positions such as Data Engineer, Data Scientist,...
• Either way, if you are interested in gathering insights from any kind of dataset, it is
extremely likely that you have spent a lot of your time playing with Excel, pivot
tables, and formulas.
1|Page
Module 1:
DATA FOR EVERYONE
Step 0: Install MySQL software
Step 1: Import Awesome Chocolates Dataset
Step 2: Learn SQL for Data Analysis with case study
The Queries
2|Page
Step 0: Install MySQL software
I am using the FREE MySQL Community Edition software to learn & practice SQL at
home. You can get it from here https://dev.mysql.com/downloads/installer/
If you have any other database software available (such as SQL Server or Oracle), you can
use them to follow this tutorial.
3|Page
At the end of these steps, your MySQL should have the awesome chocolates database.
Congratulations!
You can see this from “Schemas” tab on the workbench
CLTR + ENTER
4|Page
Working with WHERE clause
Using AND, OR, NOT and combining them to create complex queries
5|Page
6|Page
Creating reports with GROUP BY
7|Page
8|Page
GROUP BY with JOINS
9|Page
Another option is having condition
The Queries
Intermediate problems
You need to combine various concepts covered in the class to solve these
1. Print details of shipments (sales) where amounts are > 2,000 and boxes are <100?
2. How many shipments (sales) each of the sales persons had in the month of January 2022?
3. Which product sells more boxes? Milk Bars or Eclairs?
4. Which product sold more boxes in the first 7 days of February 2022? Milk Bars or Eclairs?
5. Which shipments had under 100 customers & under 100 boxes? Did any of them occur on
Wednesday?
Hard problems
These require concepts not covered in the class
1. What are the names of salespersons who had at least one shipment (sale) in the first 7
days of January 2022?
2. Which salespersons did not make any shipments in the first 7 days of January 2022?
3. How many times we shipped more than 1,000 boxes in each month?
4. Did we ship at least one box of ‘After Nines’ to ‘New Zealand’ on all the months?
5. India or Australia? Who buys more chocolate boxes on a monthly basis?
10 | P a g e
Solutions
INTERMEDIATE PROBLEMS
— 1. Print details of shipments (sales) where amounts are > 2,000 and boxes are <100?
select * from sales where amount > 2000 and boxes < 100;
— 2. How many shipments (sales) each of the sales persons had in the month of January
2022?
— 4. Which product sold more boxes in the first 7 days of February 2022? Milk Bars or
Eclairs?
— 5. Which shipments had under 100 customers & under 100 boxes? Did any of them
occur on Wednesday?
11 | P a g e
HARD PROBLEMS:
— 1. What are the names of salespersons who had at least one shipment (sale) in the
first 7 days of January 2022?
— 2. Which salespersons did not make any shipments in the first 7 days of January
2022?
select p.salesperson
from people p
where p.spid not in
(select distinct s.spid from sales s where s.SaleDate between ‘2022-01-01’ and ‘2022-
01-07’);
— 3. How many times we shipped more than 1,000 boxes in each month?
— 4. Did we ship at least one box of ‘After Nines’ to ‘New Zealand’ on all the months?
12 | P a g e
— 5. India or Australia? Who buys more chocolate boxes on a monthly basis?
Homeworks
Import Adventure Works Dataset
Schema: humanresources
Schema: person
Schema: production
Schema: purchasing
Schema: sales
13 | P a g e
Design queries for the following reports
14 | P a g e
Module 2:
BUSSINESS INTELLIGENCE ANALYST
15 | P a g e
How to load and clean-up data with Power BI
Understanding Power BI Desktop UI
Open Power BI Desktop application. After you exit the welcome splash screen, you will see
the blank Power BI application. Let’s understand this screen. Here is an illustration explaining
11 important features / buttons in Power BI Desktop.
1. Ribbon. Find most important and regular stuff in Home ribbon. Navigate to other
ribbons for specific functionality.
2. Get Data. Use this button to get data from almost anywhere – Excel files, websites,
databases, APIs etc.
3. View selection, by default you will be on Report view. Change to data or model
view to see behind scenes.
4. Fields Access the tables and fields (columns) of your data here. Use them in
visuals (5) or filters (7) etc.
5. Visualizations add charts, tables, maps, filters etc to the report from here.
6. Visual Fields, Format and analytics use this area to set up and customize your
visualizations (charts etc.) Note the paint-roller, use it to edit colors, fonts, settings etc.
7. Filters - set up chart, page, report level filters here. Anything you restrict will be
removed from all the linked items.
8. Canvas this is where you construct your reports.
16 | P a g e
9. Save your Power BI reports by pressing CTRL+S or clicking on this button. They
will be saved as PBIX files.
10. Publish the reports with this. You can publish them to online (either free
PowerBI.com account or paid plans) so that others can access your reports.
11. Add more pages to your report using the + button.
17 | P a g e
How to build a data model in Power BI
Imaging a big black box with all your tables and any relationships between them along with
the measures you have defined. This black box is your data model.
Other common names for data model are Cube, tabular model or simply model.
Relationships
You can link two tables based on a column. This is called relationship.
For example,
Say have two tables – Sales & Customers.
You can link Sales table and Customers table based on Customer ID. We then say Sales &
Customer tables are related.
It means, both columns have the same meaning.
There are two kinds of relationships.
1. One to many relationships: a value in one table is linked to one or more values in
another table. Example: Customers to Sales relationship. Each customer appears once in
Customers table but can have many matching transactions in Sales table.
2. Many to many relationships: Each value in one table can be linked to one more more
values in other table and vice-a-versa. For example: People and Projects. Each person
can be part of any number of projects. Each project can have one or more persons.
18 | P a g e
Measures
Measure or calculations are what gets displayed in visuals / tables / cards.
The Count of Name, Average Salary things we used earlier are measures.
There are three kinds of measures in Power BI.
o Implicit measures: These are automatically created when you drop a filed in the “Value”
area of a chart / visual. Example: Count of Name.
o Explicit measures: These are the ones you create by using DAX language. Example:
=SUM(Table1[Salary])
o Quick measures: These are same as ‘explicit measures’ but instead of typing the DAX
formula, you use Power BI quick measure feature to make them.
You can create measures by right clicking on a table (area 4 in the Power BI Desktop UI) or
clicking on the “New Measure” button on the ribbon.
19 | P a g e
Geographic Sales Visual
20 | P a g e
Saving Power BI workbooks
o File → Save
You can use two methods to change the calculations for the charts.
To change the calculation of a chart with default options, follow below steps.
DAX stands for Data Analysis eXpressions. This is a language for calculating things with
Power Pivot.
Sums up Amount column in the sales and presents it wherever you use this [Total
Amount] measure.
21 | P a g e
Adding measures with DAX
Power Pivot
Power Pivot is a calculation engine for Power BI. You can use Power Pivot to model
complex data, set up relationships between tables, calculate things to be show in value
field area of tables or visuals.
Think of Power Pivot as a calculation layer between your data and outputs. You can tell
Power Pivot how you want your calculations done thru a language called as DAX and Power
Pivot can give the answers. It is an extremely fast & scalable software.
This is quite different from normal Excel charts, but once you get used to it, you will see the
true power of Power BI visualizations.
22 | P a g e
Here are some of the common questions you may have about Power BI report interactions.
Simple, click or touch the selected item again. The interaction will be gone.
Select any visual, go to Format ribbon. Now click on “Edit interactions” button. This will show
interaction buttons on top of all your visuals. Click on do not interact button (looks like no
entry sign).
You can use the “Edit interactions” button to change the style of interaction. There are three
possible interactions (as depicted to the right).
1. Filter
2. Highlight
3. No interaction
23 | P a g e
Step by step instructions for our first Power BI report:
1. Load the employee data into Power BI.
2. Add a column chart.
o Department on axis
o Name (count of name) in values area
3. Add pie chart
o Gender as Legend
o Name (count of name) in values area
4. Add a table with name, age, rating and salary fields
5. Add a slicer with manager as field
Select the table. Click on down arrow symbol next to Rating and apply conditional formatting
> Background color. Set up a color scale as shown below.
24 | P a g e
Data bar for Salary:
Click on conditional formatting for salary, set up data bars as shown below.
From Home ribbon in Power BI, click on Text box and type your report title in that. Format the
text and position it on the top.
Play with slicer or charts to see powerful insights from this report.
25 | P a g e
How to share / publish your reports?
o Email or share the file: this is the simplest method. Just email or share the file with your
audience. They will need Power BI Desktop to view the reports though. Also, they will
need to access the source data sets to be able to refresh or update the reports.
o Publish to Power BI online: This is the recommended way to sharing your reports. But
you do need PowerBI account (either paid or free) to be able to publish the files to online
workspace. Once you publish your reports to the workspace, you can invite others to view
them or pin parts of it to a dashboard etc.
o Share to Mobile / Tablet via Power BI app: Once you publish the reports to Power BI
workspace, others can view the reports on web or on mobile / tablet apps by accessing
the workspace.
Refresh refers to the concept of updating all the data, calculations and visuals based on
source data changes. You can manually trigger refresh by clicking on the “Refresh” button in
Power BI Desktop Home ribbon.
You can also schedule refresh for online published reports so that every day (or whatever
frequency you determine) Power BI online will refreshes your data and updates the
published reports.
With Power BI, you create once, use forever. As your business data changes, all you need
to do is, refresh the report. This will automatically fetch any new data from your source,
update all calculations and visuals. If you publish the report again, this will replace the online
version with new one so your colleagues or clients can access updated reports easily.
What if your data format changes?
For example, if you add new columns or rename things, then you may need to rebuild some
visuals or calculations. You will notice any broken items upon refresh and you can easily fix
them.
26 | P a g e
Use SQL with Power BI
Report
27 | P a g e
Understanding trends & creating forecast in Power BI
Trend of Customers
Always make measure !
They make your reports FLEXIBLE
28 | P a g e
Forecasting Power BI
29 | P a g e
Projects
Ecommerce Sales Dashboard
30 | P a g e
Amazon Product Review Dashboard
Summary
Product Table
31 | P a g e
Customer Complaints Dashboard
Finance Report
32 | P a g e
Mall Sales Analytics
33 | P a g e