B9_PowerBI_CB
B9_PowerBI_CB
BỘ MÔN KẾ TOÁN
GIỚI THIỆU
POWER BI CƠ BẢN
CƠ BẢN VỀ POWER BI
• Power BI là công cụ phân tích dữ liệu kinh doanh chia sẻ thông tin một cách
dễ dàng và chi tiết; Kết nối dữ liệu dễ dàng, hiển thị nhanh trên Dashboard –
bảng điều khiển, các báo biểu động và đa dạng cập nhật theo thời gian thực.
• Power BI là tập hợp nhiều ứng dụng và connectors. Biến các nguồn dữ liệu
không liên quan, thành thông tin chi tiết mạch lạc, trực quan và tương tác.
Nguồn dữ liệu đa dạng, có thể giản tệp Excel hoặc bảng của website, đến
Azure hoặc AWS.
• Đảm báo tính bảo mật cao là yếu tố quan trọng trong thời đại này.
6
THE PROJECT
The management team needs a way to track KPIs (sales, revenue, profit,
TH returns), compare regional performance, analyze product-level trends, and identify
BRIEF
E high-value customers.
All you’ve been given is a folder of raw csv files, which contain
information about transactions, returns, products, customers,
and sales territories.
Use Power BI Desktop to:
TH • Connect and transform the raw data
OBJECTIVE
E •
•
Build a relational data model
Create calculated columns and measures
with DAX
• Design an interactive dashboard to
visualize the data
*This data is provided by Microsoft for informational purposes only as an aid to illustrate a concept. These samples are provided “as is” without warranty of any kind. The example
companies, organizations, products, domain names, e-mail addresses, people, places, and events depicted herein are fictitious, and no association with any real company,
organization, product, domain name, e-mail address, person, place, or event is intended or should be inferred.
SETTING EXPECTATIONS
1 What you see on your screen may not always match mine
• Power BI Desktop features are updated frequently, with new versions released each
month
• NOTE: Power BI is currently only compatible with PC/Windows (not available for Mac)
*Copyright Maven
Analytics, LLC
MEET POWER BI
*Copyright Maven
Analytics, LLC
WHY POWER BI?
EXCEL POWER BI
*Copyright Maven
Analytics, LLC
INSTALLING POWER BI DESKTOP
Global > Preview Current File > Data Current File > Regional
Features Load Settings
Select all available preview features by Make sure the following options are NOT Select “English (United States)” from
default (these change with each selected: the dropdown menu (this will align
monthly release) • Update or delete relationships when refreshing with the data in course project files)
data
• Autodetect new relationships after data is loaded
• Time Intelligence > Auto date/time
HEY THIS IS IMPORTANT!
Options under CURRENT FILE need to be adjusted every time you open a new Power BI workbook (these settings do not persist
across new .pbix files)
POWER BI WORKFLOW
Data models
are
configured in
the Model View
POWER BI WORKFLOW
Data models
are
configured in
the Model View
Data models
are
configured in
the Model View
Visuals &
reports are
designed in the
Report View
HELPFUL RESOURCES
Update Screenshot
The Microsoft Power BI The Microsoft Power BI YouTube Power BI User Groups (Power BIUG)
blog Channel publishes demos, are communities of users,
(powerbi.microsoft.com/ feature summaries, and which include both local meet-
blog) publishes monthly advanced tutorials (check ups and helpful online forums
summaries to showcase out “Guy in a Cube” too!) (pbiusergroup.com)
new features
MONTHLY UPDATES
Power BI Desktop
https://docs.microsoft.com/en-us/power-bi/fundamentals/desktop-
latest-update
Power BI Service
https://docs.microsoft.com/en-us/power-bi/fundamentals/service-
whats-new
Power Platform
https://learn.microsoft.com/en-us/dynamics365/release-plans/
CONNECTING & SHAPING DATA
*Copyright Maven
Analytics, LLC
CONNECTING & SHAPING DATA
In this section we’ll connect to source files and cover some of the most
common techniques for extracting, cleaning, and shaping data to prepare it for
modeling and analysis
The Query Editor Connection Modes • Introduce different types of connectors and
connectivity modes available for getting
data into Power BI
Data QA & Profiling Table Transformations • Review tools for checking data quality and key
profiling metrics like column distribution, empty
values, errors and outliers
Calendar Tools Combining Queries
• Transform tables using text, numerical and
date/time tools, pivot and group records, and
create new conditional columns
Power BI Desktop essentially has two distinct environments: a front-end and a back-end
• The front-end includes the Data, Model & Report views, where most of the modeling, analysis and
visualization takes place
• The back-end includes the Power Query Editor, where raw data is extracted, transformed, and loaded to
the front-end (ETL)
BACK-END FRONT-END
• Connect & extract data using pre-built • Build data models by creating table
connectors relationships between primary and
foreign keys
• Profile & QA the data to explore, clean and
prepare it for modeling and analysis • Add calculated measures & columns using
Data Analysis Expressions (DAX)
• Transform & shape tables to add new features,
modify values, group records, or sort and • Design reports to visualize the data and
filter columns create interactive, dynamic
dashboards
• Merge or append queries to join and
combine them prior to loading to the • Publish & share your Power BI
front-end workbooks using Power BI Service
(cloud application)
• Perform advanced transformations using
custom M code (out of scope for this
course) *Copyright Maven
Analytics, LLC
TYPES OF DATA CONNECTORS
Queries Pane
(list of all Applied Steps
queries) (like a
macro)
Table Preview
*In older versions of Power BI, the Transform Data option may be
QUERY EDITING TOOLS
The HOME tab includes general settings and common table transformation
tools
The TRANSFORM tab includes tools to modify existing columns (splitting/grouping, transposing,
extracting text, etc.)
The ADD COLUMN tools create new columns (based on conditional rules, text operations,
calculations, dates, etc.)
BASIC TABLE TRANSFORMATIONS
Sort values (A-Z, Low-High, Change data type (date, $, %, text,
etc.) etc.)
Promote
headers
Duplicate, move
or
Choose or remove columns rename
Tip: use the “Remove Other columns
Columns” option if you always
want a specific set Tip: Right-click column
headers to access
Keep or remove rows common tools
Thanks!
-ETL
Product Category
Lookup Product
Subcategory Lookup
PRO TIP: STORAGE & CONNECTION MODES
Power Query can connect to data from various database sources including SQL Server,
MS Access, MySQL, PostgreSQL, Oracle, SAP, and more
*Copyright Maven
Analytics, LLC
EXTRACTING DATA FROM THE WEB
Power Query includes a native Web connector for importing web-hosted files (csv,
xlsx, etc.) or scraping URLs for anything that Power Query can identify as a
structured table
https://en.wikipedia.org/wiki/
List_of_asset_management_firms
PRO TIP: Profiling tools are a great way to quickly find and address common data quality issues in
one place, instead of having to manually apply multiple tools or filters
DATA PROFILING: COLUMN DISTRIBUTION
*Copyright Maven
Analytics, LLC
DATA PROFILING: COLUMN PROFILE
Count = 293
(total number of
values in column)
Distinct Count =
119
Unique =
(total number of Hover over the value
82 whether
distinct values, distribution bar for suggested
they
(total number of values that appear
appear once or transformations and additional
exactly once)
Min ×)
multiple Max options
(lowest and
highest
observed
values)
Note:
Typically
only useful
for
TEXT TOOLS
We’re looking to better understand where our 3. Use transformation steps to clean up and
customers may be coming from, based on their capitalize the domain names (i.e. “Adventure
email domains. Works”)
Could you please create a new column in the 4. Save & Apply changes
customer table that will allow us do this?
Thanks!
-ETL
SOLUTION: TEXT TOOLS
Solution Preview
NEW MESSAGE
Hi!
Thanks!
-ETL
NUMERICAL TOOLS
We don’t really need to store these values 5. Return the tables to their original state
anywhere, so make sure to restore the tables back
to their original state once you’re done pulling the
stats.
Thank you!
-ETL
SOLUTION: NUMERICAL TOOLS
Solution Preview
NEW MESSAGE
1. What is our average product cost? ($413.66)
From: Ethan T. Langer (Analytics Manager) 2. How many colors do we sell our products in?
Subject: Need some stats for leadership (10)
3. How many distinct customers do we have?
Hi again, (18,148)
Leadership is asking us to validate some high-level
4. What is the maximum annual customer
stats about our products and customers. Can you
please help me answer the following questions? income? ($170k)
We don’t really need to store these values 5. Return the tables to their original state
anywhere, so make sure to restore the tables back
to their original state once you’re done pulling the
stats.
Thank you!
-ETL
DATE & TIME TOOLS
Date & Time tools are relatively straight-forward, and include the following options:
• Age: Difference between the current date and the date in each row
PRO TIP: Load up a table containing a single date column and use Date tools to build out an
entire calendar table
*Copyright Maven
Analytics, LLC
CREATING A CALENDAR TABLE
*Copyright Maven
Analytics, LLC
CHANGE TYPE WITH LOCALE
1) Left click the data type 2) Select Date as the data type and 3) Confirm that the data type is correctly
icon in the column English (United States) as the locale for recognized. You should see a calendar icon
header and select the all datasets in this course next to the column name in the header
Using Locale option (regardless of your actual location) and no errors in the column
*Copyright Maven
Analytics, LLC
PRO TIP: ROLLING CALENDARS
Click the 𝒇𝒙 icon to add a custom step, and enter the following
Query
*Copyright Maven
Analytics, LLC
ASSIGNMENT: CALENDAR TABLES
Key Objectives
NEW MESSAGE Add the following columns to the
calendar table:
From: Ethan T. Langer (Analytics Manager)
Subject: New date fields 1. Month Name (e.g. “January”)
2. Month Number (e.g. “1”)
Hi,
3. Start of Year (e.g. “1/1/2020”)
We need to add a few fields to our calendar
table to help us analyze sales trending over 4. Year (e.g. “2020”)
time.
Thanks!
-ETL
SOLUTION: CALENDAR TABLES
Solution Preview
NEW MESSAGE
Hi,
Thanks!
-ETL
*Copyright Maven
Analytics, LLC
INDEX COLUMNS
UPSTREAM DOWNSTREAM
PRO TIP: Use the Folder option (Get Data > More > Folder) to append all files within a specified
folder (assuming they share the same structure); as you add new files, simply refresh the
query and they will automatically append!
PRO TIP: APPENDING FILES FROM A FOLDER
DATA SOURCE SETTINGS
Data Source Settings allow you to manage existing data connections, file paths
and permissions
Parameter name
(Name of the
query/table)
Parameter type
(Any value, text,
date, etc.)
Parameter value
(Any value, list,
query) Update Server & Database
connection text values
with parameters
Parameter type
(Default &
current)
REFRESHING QUERIES
PRO TIP: If you are more comfortable working in Excel, build your models there first then
import to Power BI!
*In older versions of Power BI, this import option may be called “Excel *Copyright Maven
Workbook Contents” Analytics, LLC
POWER QUERY BEST PRACTICES
*Copyright Maven
Analytics, LLC
CREATING A DATA MODEL
This Calendar Lookup table contains attributes about each date (month,
year, quarter, etc.)
This Product Lookup table contains attributes about each product_id (brand,
SKU, price, etc.)
These are foreign keys (FK) These are primary keys (PK)
They contain multiple instances of They uniquely identify each row of
each value, and relate to primary keys the table, and relate to foreign keys
in dimension tables in fact tables
RELATIONSHIPS VS. MERGED TABLES
Can’t I just merge queries or use lookup functions to pull everything into
one single table?
- Anonymous confused man
Original Fact Table Attributes from Calendar Lookup Attributes from Product Lookup
fields table table
Menu Ribbon
(Home,
Help)
Model canvas
Launch the Manage Relationships dialog Editing tools allow you to activate or deactivate
box or double-click a relationship relationships and manage cardinality and filter
to modify it direction – more on that soon!
*Copyright Maven
Analytics, LLC
STAR & SNOWFLAKE SCHEMAS
Hey there,
-Dana
PRO TIP: ACTIVE & INACTIVE RELATIONSHIPS
The Sales Data table contains two date fields (Order Date & Stock
Date), but there can only be one active relationship to the Date key
in the Calendar table
You can set relationships to active or inactive from either the Edit
Relationships
dialog box or the Properties (you must deactivate one before
PRO TIP: ACTIVE & INACTIVE RELATIONSHIPS
The Sales Data table contains two date fields (Order Date & Stock
Date), but there can only be one active relationship to the Date key
in the Calendar table
You can set relationships to active or inactive from either the Edit
Relationships
dialog box or the Properties (you must deactivate one before
RELATIONSHIP CARDINALITY
There are MANY instances of each Product Key in the Sales table
(noted by an asterisk *), since there are multiple sales for each
product
EXAMPLE: ONE-TO-ONE CARDINALITY
Product Lookup Price Lookup
• If we try to connect the tables above using product_id, we’ll get a many-to-
many relationship
warning since there are multiple instances of product_id in both tables
• Even if we force this relationship, how would we know which product was
actually sold on each date – Cream Soda or Diet Cream Soda?
CONNECTING MULTIPLE FACT TABLES
PRO TIP: Arrange lookup tables above fact tables in your model as a visual reminder that filters
always flow downstream
EXAMPLE: FILTER FLOW
In this model, the only way to filter both Sales and
Returns data by Territory is to use the Territory Key from
the lookup table, which is upstream and related to
both fact tables
Filtering by Returns
Data[Territory Key]
Filtering by Territory Filtering by Sales
Lookup[Territory Key] Data[Territory Key]
BI-DIRECTIONAL FILTERS
*The “Apply security filter in both directions” option relates to row-level security (RLS) settings, which are *Copyright Maven
out of scope for this course Analytics, LLC
EXAMPLE: BI-DIRECTIONAL FILTERS
Filtering by Returns
Data[Territory Key]
Filtering by Territory Filtering by Sales
Lookup[Territory Key] Data[Territory Key]
EXAMPLE: BI-DIRECTIONAL FILTERS
Filtering by Returns
Data[Territory Key]
Filtering by Territory Filtering by Sales
Lookup[Territory Key] Data[Territory Key]
AMBIGUITY
Solution Preview
NEW MESSAGE 1. Larry must have changed the
relationship between Returns Data and
From: Dana Modelle (Analyst) Product Lookup to bi-directional, and
Subject: Larry’s gone rogue! filtered his matrix using product_id
from the Returns table
Hey there, we’ve got another problem.
• Road bike (Road-650 Black, 44)
Larry from Sales just sent me this screenshot. I
think he must have downloaded our Power BI • Product 338 doesn’t exist in the
model and messed with some relationships,
Returns table, so it was
because I KNOW we had sales for product 338.
excluded when that filter
Can you help diagnose what’s going on, and 2 context passed to the Sales
prevent him from doing this again? . table
-Dana
Model layouts allow you to create custom views to show specific portions of
large, complex models
• Here we’ve created a Sales View displaying only tables related to sales, and a Returns View
displaying only tables related to returns (Note: this doesn’t actually create duplicate tables)
DATA FORMATS & CATEGORIES
In the Data pane, right-click This hierarchy contains Right-click another field (like
a field and select Create “Continent”, and is named “Country”) and select Add to
hierarchy “Territory Hierarchy” Hierarchy (or drag it in!)
ASSIGNMENT: HIERARCHIES
Key Objectives
NEW MESSAGE 1. Create a new hierarchy based on
the Start of Year field, and name it
From: Dana Modelle (Analyst) “Date Hierarchy”
Subject: Adding a date hierarchy
2. Right-click or drag to add fields until
Good morning! your hierarchy contains the following
Hoping you can help with a quick request. (in this order):
Since we’ll be doing a lot of time-series analysis, • Start of Year
Ethan asked us to add a date hierarchy to the
model so that users can quickly view trends at • Start of Month
any level of granularity (year, month, day, etc.)
• Start of Week
Please get that added before our afternoon call.
Thanks! • Date
-Dana
3. Add your new hierarchy to the matrix
visual (on rows) and practice drilling
up and down between each level of
granularity
SOLUTION: HIERARCHIES
Solution Preview
NEW MESSAGE
Good morning!
-Dana
DATA MODEL BEST PRACTICES