Power BI Tutorial
Power BI Tutorial
Power BI is a suite of business analytics tools from Microsoft that enables users to
visualize and share insights from their data. It allows individuals and organizations to
transform raw data into meaningful, interactive visualizations, helping with data-driven
decision-making. Power BI consists of several components, each serving specific needs
for users in terms of data analysis, sharing, and reporting.
1. Power BI Desktop:
Purpose: Power BI Desktop is a free, Windows-based application for creating data
reports and visualizations. It is used to import, transform, and model data and then
design reports.
Key Features:
2. Power BI Service:
Purpose: The Power BI Service (also called Power BI Online) is a cloud-based platform
for sharing and collaborating on Power BI reports and dashboards.
Key Features:
Key Features:
Key Features:
Create reports with exact page formatting
Includes features like tables, charts, and text boxes
Built-in data connectors for pulling in datasets
Can be used to create pixel-perfect reports that can be printed or exported as
PDFs
1. Data Connectivity:
2. Data Transformation:
Power BI includes Power Query, a tool for transforming and cleaning data before
analysis. Power Query allows users to remove duplicates, filter rows, change data
types, and apply various transformations.
3. Data Modelling:
Users can define relationships between different data tables, enabling advanced
analysis and calculations using the DAX language.
Supports star schema and snowflake schema for organizing data models.
4. Visualizations:
Power BI offers a wide variety of built-in visuals, including bar charts, line charts,
pie charts, tables, maps, and more.
Users can customize visualizations with themes, formatting options, and tooltips
to enhance the user experience.
Power BI also allows importing custom visuals developed by third-party vendors or
the community.
5. Advanced Analytics:
Power BI supports the use of DAX for creating custom calculations, aggregations,
and measures.
Integrates with Azure Machine Learning and R for advanced predictive analytics
and machine learning models.
Built-in trend lines, clustering, and forecasting for deeper analysis.
Dashboards and reports can be shared with colleagues or stakeholders via the
Power BI Service.
Users can collaborate, comment, and create alerts based on specific data
conditions.
Integration with Microsoft Teams allows sharing reports directly within
collaborative spaces.
8. Mobile Access:
Power BI includes robust security features, such as row-level security (RLS), which
restricts data access based on user roles.
Integration with Azure Active Directory for managing users and roles.
Audit logs and monitoring capabilities for enterprise-level governance.
Seamless integration with Microsoft Office tools (Excel, Teams, SharePoint) and
Azure services for enhanced data analytics and collaboration.
Power BI also integrates with other third-party services through APIs, connectors,
and custom visuals.
Data preparation is a critical step in the Power BI process, ensuring that the data is clean,
transformed, and structured properly for analysis. This stage involves connecting to
various data sources, transforming data using Power Query, and modelling it for
insightful visualizations. The preparation process helps optimize Power BI reports and
dashboards for better performance and accuracy.
Power BI supports a wide range of data sources, enabling users to import, connect, and
analyse data from diverse systems. Here are the primary data sources supported:
Excel:
Power BI easily integrates with Excel files (.xlsx, .xls) for importing both tables
and ranges.
Users can import data from individual sheets, named ranges, or even Power Pivot
models in Excel.
SQL:
CSV Files:
CSV files are commonly used for data exchange and can be easily imported into
Power BI.
Data is typically read row by row and automatically detected for column headers,
types, and formats.
APIs:
Power BI can connect to various REST APIs to fetch data from web services,
applications, and other external sources.
Users can import JSON or XML data from APIs and transform it for analysis.
The Web connector in Power BI is used for API-based connections.
Power BI allows live connections to data sources (e.g., SQL Server, Analysis
Services) where data is not imported but queried directly in real time.
Live data connections provide real-time insights but may impact report
performance depending on the query size and complexity.
Power Query is the primary tool in Power BI for data extraction, transformation, and
loading (ETL). It allows users to perform complex data shaping tasks without the need for
programming knowledge.
Extraction: Power Query allows users to connect to multiple data sources (Excel,
SQL, web services, etc.) and import data into Power BI for analysis.
Load: Once the data is transformed, it can be loaded into Power BI for use in
reports and visualizations. The loaded data is stored in the Power BI data model.
2. M Language Basics
M Language: Power Query uses a formula language called M to define data
transformation steps. This language is the backbone of how queries are structured
behind the scenes.
This line of code filters rows where the "Age" column is greater than 30.
Filtering:
Power Query allows filtering out unwanted rows based on specific conditions,
such as removing null values or filtering records by date ranges or categories.
Merging:
Appending:
Appending allows you to stack multiple tables with the same structure into
one table. This is useful for combining data from different sources that have
the same schema, like monthly sales data.
Pivoting allows transforming rows into columns (e.g., converting sales data
into a wide format). Unpivoting is the opposite—turning columns into rows for
better data analysis.
Grouping:
Power Query allows you to group data by one or more columns and then apply
aggregate functions like sum, average, or count.
Data modelling is a key aspect of Power BI that ensures your reports and dashboards are
accurate, efficient, and scalable. Here are best practices for building a robust data model
in Power BI:
Star Schema: A central fact table (e.g., sales data) connected to dimension
tables (e.g., product, time, geography). This approach is simple and easy to
navigate.
Snowflake Schema: Similar to the star schema but with additional
normalization in dimension tables. It may require more complex queries but
helps in reducing redundancy.
2. Create Relationships Between Tables:
Define relationships between tables using primary and foreign keys. Power BI
supports one-to-many and many-to-many relationships.
Ensure that dimension tables are connected to fact tables, and avoid circular
dependencies.
3. Use Data Types and Format Consistently:
Ensure that the data types of columns are correctly set (e.g., date, text,
number). This ensures that calculations and relationships work properly.
Consistent formatting of data (e.g., date format, currency, decimal points)
improves readability and avoids issues during analysis.
4. Avoid Using Too Many Columns in Fact Tables:
Keep the fact table simple and only include necessary columns (e.g., sales
amount, quantity). Do not include dimension attributes in the fact table, as
these should be in dimension tables.
5. Leverage DAX for Calculated Columns and Measures:
Power BI allows you to set up RLS to restrict access to data based on user
roles. This is crucial for ensuring that sensitive information is protected and
only accessible to authorized users.
8. Keep the Model Simple and Intuitive:
Create models that are easy to understand and use. Avoid overly complex
data structures or excessive numbers of relationships that can confuse report
creators and consumers.
Data modeling in Power BI is the process of organizing and structuring data into a
coherent and efficient format for analysis and visualization. A well-designed data model
improves report performance, facilitates meaningful analysis, and ensures accurate
insights.
Relationships in Power BI define how tables are connected and interact with one another,
based on shared fields.
Primary Key:
A field in one table that refers to the primary key in another table.
Used to establish relationships between tables, e.g., "CustomerID" in a Sales
table linking to "CustomerID" in the Customer table.
2. Types of Relationships
One-to-Many (1:n):
Many-to-Many (*m:n):
Occurs when multiple records in one table relate to multiple records in another
table.
Power BI supports many-to-many relationships, but they should be used
carefully due to potential complexity and performance issues.
One-to-One (1:1):
Schemas describe how tables are organized and related in a data model.
1. Star Schema
Structure:
A central fact table (e.g., Sales) connected to multiple dimension tables (e.g.,
Product, Customer, Date).
Advantages:
2. Snowflake Schema
Structure:
An extension of the star schema where dimension tables are normalized into
multiple related tables (e.g., Product table connected to a Category table).
Advantages:
Disadvantages:
2. Dimension Tables
Key Differences:
Model Optimization
1. Performance Tuning
2. Cardinality
3. Storage Modes
Import Mode:
Role-Playing Dimensions
Role-playing dimensions occur when the same dimension table is used in different roles
in a model. For example, a Date table can be used as:
Introduction to DAX
1. Calculated Columns
Calculated columns are added to a table in the data model using DAX
formulas.
They perform row-level calculations, meaning each row is calculated
independently.
Useful for creating new fields (e.g., "Profit Margin = [Sales] - [Cost]").
Drawback: Calculated columns increase model size and processing time.
2. Measures
1. Row Context
Example:
Profit = [Sales] - [Cost]
2. Filter Context
Example: If a visualization filters data by "Region = North," the filter context limits the
calculation to data for that region.
Key Difference:
1. Aggregation Functions
DAX
2. Logical Functions
TRUE(),
4. Ranking Functions
Advanced DAX
DAX
TRUE(),
KPI (Key Performance Indicators) are created using DAX to compare actual values
against targets.
1. Debugging DAX
Profit Margin =
RETURN
Visualizations in Power BI enable users to present data insights effectively using various
chart types, custom visuals, and interaction techniques. This section explains standard
and advanced visualizations, custom visuals, and best practices for designing impactful
reports, enhanced with figures for better understanding.
1. Standard Visualizations
Bar Charts
Represent data using rectangular bars.
Types:
Line Charts
2. Advanced Visuals
Maps
Scatter Plots
3. Custom Visuals
Power BI AppSource offers a wide range of custom visuals, such as Word Clouds, Bullet
Charts, and Timeline visuals.
To install:
1. Open the Visualizations Pane.
2. Click on Import from AppSource.
3. Search for and add the desired visual.
Steps:
Python
import matplotlib.pyplot as plt
plt.show()
Color Theory
Slicers: Allow users to interactively filter data by category (e.g., date, region).
Filters: Apply to visuals, pages, or the entire report.
Bookmarks: Save specific views for storytelling and navigation.
5. Interaction Techniques
Drill through
Selecting data in one visual automatically filters other visuals on the page.
Example: Clicking on a bar in a bar chart updates a table below.
Tooltips
Conditional Formatting
Example:
Green for positive growth, red for negative growth.
Dynamic Titles
Example:
DAX