0% found this document useful (0 votes)
82 views15 pages

Power BI Tutorial

Uploaded by

Shital Shende
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
82 views15 pages

Power BI Tutorial

Uploaded by

Shital Shende
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

Introduction to Power BI

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.

Power BI Ecosystem Overview


The Power BI ecosystem includes a range of tools and services that work together to
provide a complete data analysis solution. These components are:

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:

 Connects to various data sources (databases, Excel, cloud-based data, etc.)


 Offers tools for data transformation (Power Query Editor)
 Data modelling and relationships
 Extensive library of visualizations (bar charts, line graphs, maps, etc.)
 DAX (Data Analysis Expressions) for advanced calculations
 Report creation and interactive 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:

 Hosts and shares reports created in Power BI Desktop


 Provides collaboration features (e.g., sharing, commenting)
 Allows publishing and managing dashboards
 Provides data refresh capabilities
 Includes Power BI workspaces for organizing reports and datasets
 Integration with Microsoft services like Teams and SharePoint

3. Power BI Mobile App:


Purpose: A mobile application that allows users to access their Power BI reports and
dashboards on mobile devices (smartphones and tablets).

Key Features:

 View and interact with live dashboards and reports


 Set alerts and notifications for data changes
 Touch-based navigation and gestures for mobile screens
 Share insights via email or other apps
 Real-time updates with cloud connectivity

4. Power BI Report Builder:


Purpose: Power BI Report Builder is a tool for creating paginated (printable) reports,
often used for detailed, highly formatted reports (e.g., invoices, financial reports).

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

Key Features and Capabilities of Power BI


Power BI provides a wide range of features to facilitate data analysis and reporting. Here
are some of the key capabilities:

1. Data Connectivity:

 Power BI supports connections to hundreds of data sources, including SQL


databases, Excel files, cloud-based services like Azure and Google Analytics, and
web data sources.
 Provides seamless integration with Microsoft ecosystem tools such as Excel, SQL
Server, and Azure data services.

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.

6. Collaboration and Sharing:

 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.

7. Data Refresh and Real-Time Data:


 Power BI supports scheduled data refresh, ensuring reports and dashboards are
up-to-date.
 Can connect to real-time data sources (e.g., IoT devices, social media) and display
live data updates.

8. Mobile Access:

 Power BI provides a mobile app to access reports and dashboards on-the-go,


ensuring that insights are available anytime, anywhere.

9. Security and Governance:

 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.

10. Integration with Other Microsoft Services:

 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.

2. Power BI: Data Preparation

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.

Data Sources in Power BI

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:

1. Importing Data from Various Sources:

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:

 Power BI supports connections to SQL Server databases (both on-premise and


cloud-based) using SQL authentication or Windows authentication.
 You can import data by writing SQL queries or using predefined views/tables from
the database.

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.

2. Connecting to Live and On-Premise Data Sources:

Live Data 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.

On-Premise Data Sources:

 Power BI supports connecting to on-premise data sources such as SQL Server,


Oracle databases, and others.
 The Power BI Gateway facilitates secure data transfer between on-premise data
sources and the cloud, enabling scheduled refreshes and live connections for
hybrid scenarios.

Power Query in Power BI

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.

1. Data Extraction, Transformation, and Load (ETL)

Extraction: Power Query allows users to connect to multiple data sources (Excel,
SQL, web services, etc.) and import data into Power BI for analysis.

Transformation: Power Query offers a wide range of data transformation


operations, such as filtering, grouping, sorting, merging, and changing data types.
Common transformations include:

 Filtering rows (e.g., removing unwanted data points)


 Grouping data (e.g., aggregating sales by region)
 Changing data types (e.g., converting strings to dates)
 Removing duplicates (e.g., to clean up the dataset)

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.

 Syntax: M is a functional language, meaning it applies functions to data in a


series of steps. It is used to filter, sort, merge, or transform data.
 Structure: M code is generated automatically as you use the Power Query UI,
but you can also manually write M queries for more advanced data
manipulation.
 Example: A simple M expression could be:

= Table.SelectRows(Source, each [Age] > 30)

This line of code filters rows where the "Age" column is greater than 30.

3. Common Transformations in Power Query

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:

 Merging is the process of combining two tables based on common columns


(similar to SQL joins). Power Query supports inner, outer, left, and right joins to
merge data.

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 and Unpivoting:

 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.

Best Practices for Data Modelling in Power BI

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:

1. Use Star Schema or Snowflake Schema:

 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:

DAX (Data Analysis Expressions) is a formula language used for calculations in


Power BI. Create calculated columns (for row-level calculations) and measures
(for aggregation-level calculations) to enhance the model.
6. Optimize Performance with Data Aggregation:

 Consider using aggregated tables or summary tables to improve performance,


especially when dealing with large datasets.
 Use Direct Query for real-time data connections, but keep in mind the trade-
off between performance and real-time data.
7. Implement Row-Level Security (RLS):

 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.

3. Power BI: Data Modeling

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.

Understanding Data Relationships

Relationships in Power BI define how tables are connected and interact with one another,
based on shared fields.

1. Primary Keys and Foreign Keys

Primary Key:

 A unique identifier for each record in a table.


 Used to uniquely define a row in a table, e.g., "CustomerID" in a customer
table.
Foreign 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):

 The most common relationship type in Power BI.


 A single value in one table (e.g., a CustomerID in the Customer table)
corresponds to multiple related values in another table (e.g., CustomerID in
the Sales table).

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):

 A less common relationship where each record in one table corresponds to


exactly one record in another table.

Star vs. Snowflake Schemas

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:

 Simpler structure, easier to understand.


 Optimized for query performance.
 Ideal for analytical and reporting purposes.

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:

 Reduces data redundancy.


 Useful for highly normalized data sources.

Disadvantages:

 More complex and slower in performance compared to star schema.


 Requires additional joins, which can impact query speed.

Fact and Dimension Tables


1. Fact Tables

 Store transactional or event data.


 Contain measurable data (e.g., Sales Amount, Quantity).
 Examples: Sales, Orders, Revenue.
 Typically have a large number of rows.

2. Dimension Tables

 Store descriptive attributes related to facts (e.g., Product Name, Customer


Name).
 Examples: Product, Customer, Geography.
 Typically have fewer rows than fact tables and contain unique records.

Key Differences:

Aspect Fact Table Dimension Table

Data Type Numeric, measurable Textual, descriptive

Purpose Quantitative analysis Qualitative categorization

Size Large (more rows) Smaller (fewer rows)

Model Optimization

Optimization ensures that Power BI models are efficient and performant.

1. Performance Tuning

 Avoid unnecessary columns: Only include relevant fields in your tables.


 Use relationships wisely: Avoid creating excessive relationships, especially
many-to-many.
 Aggregate data: Create summary tables for commonly used aggregations.
 Avoid calculated columns: Prefer measures over calculated columns as they
are more efficient.

2. Cardinality

 Refers to the uniqueness of data in a column.


 Low Cardinality: Few unique values (e.g., "Yes/No"). Easier to process.
 High Cardinality: Many unique values (e.g., Customer IDs). Can slow down
performance.

3. Storage Modes

Import Mode:

 Data is imported and stored in Power BI's in-memory engine.


 Offers fast performance.
 Recommended for most scenarios, especially when working with static or
semi-static data.

Direct Query Mode:


 Data remains in the source system, and queries are sent directly to the
database.
 Enables real-time reporting.
 Performance depends on the source system and query complexity.
 Use sparingly, as it can result in slower performance.

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:

 Order Date: Date when an order was placed.


 Ship Date: Date when an order was shipped.
 Delivery Date: Date when an order was delivered.

Best Practices for Role-Playing Dimensions:

 Duplicate Tables: Create duplicate instances of the dimension table (e.g.,


Date Table for each role) to manage multiple relationships.
 DAX Measures: Use DAX functions to specify roles dynamically without
duplicating tables.

4.Power BI: Data Analysis with DAX (Data Analysis Expressions)


DAX (Data Analysis Expressions) is a formula language in Power BI used to create custom
calculations, aggregations, and measures. It enables users to extract meaningful insights
from data models and design dynamic reports. DAX combines functions, operators, and
formulas to manipulate data effectively.

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

 Measures are calculations applied dynamically during report rendering.


 They aggregate data across rows based on the context of the visualization
(e.g., "Total Sales = SUM([Sales])").
 Highly efficient and recommended over calculated columns for aggregations.
 Do not increase model size.

Row Context vs. Filter Context

1. Row Context

 Refers to the current row being evaluated in a table.


 Used in calculated columns or iterating functions like SUMX.

Example:
Profit = [Sales] - [Cost]

This is evaluated for each row in the table.

2. Filter Context

 Refers to filters applied to a table or model during visualization or DAX


evaluation.
 Affects measures and calculated fields.

Example: If a visualization filters data by "Region = North," the filter context limits the
calculation to data for that region.

Key Difference:

 Row context evaluates one row at a time.


 Filter context evaluates all rows but filters them based on conditions.

Core DAX Functions

1. Aggregation Functions

 Perform mathematical operations on data:


SUM: Adds up all values in a column.

DAX

Total Sales = SUM(Sales[Amount])

 COUNT: Counts rows or values in a column.


DAX

Order Count = COUNT(Orders[OrderID])

 AVERAGE: Calculates the mean of values in a column.


DAX

Avg Sales = AVERAGE(Sales[Amount])

2. Logical Functions

 Allow conditional logic in DAX formulas:


 IF: Implements basic conditional logic.
DAX

High Sales = IF(Sales[Amount] > 10000, "Yes", "No")

 SWITCH: Simplifies multiple conditional checks.


DAX

Sales Category = SWITCH(

TRUE(),

[Amount] > 10000, "High",

[Amount] > 5000, "Medium",


"Low"

3. Time Intelligence Functions

 Enable calculations over time periods.


 DATESYTD: Calculates year-to-date values.
DAX

YTD Sales = TOTALYTD(SUM(Sales[Amount]), Dates[Date])

 PARALLELPERIOD: Shifts data for a specific period (e.g., previous month).


DAX

Previous Month Sales = CALCULATE(SUM(Sales[Amount]), PARALLELPERIOD(Dates[Date],


-1, MONTH))

 DATEADD: Adjusts the date by a specified interval.


DAX

Sales Last Year = CALCULATE(SUM(Sales[Amount]), DATEADD(Dates[Date], -1,


YEAR))

4. Ranking Functions

 Provide ranking and ordering functionality:


 RANKX: Ranks values based on a specific expression.
DAX

Sales Rank = RANKX(ALL(Sales[Product]), SUM(Sales[Amount]), , DESC)

 TOPN: Returns the top N rows based on a condition.


DAX

Top 5 Products = TOPN(5, Products, SUM(Sales[Amount]), DESC)

Advanced DAX

1. Context Modification with CALCULATE and FILTER

 CALCULATE: Changes the filter context for a calculation.


DAX

Sales for Region = CALCULATE(SUM(Sales[Amount]), Sales[Region] = "North")

 FILTER: Applies a filter condition to a table.


DAX

High Value Orders = CALCULATE(SUM(Sales[Amount]), FILTER(Sales, Sales[Amount] >


10000))

2. Dynamic Measures and KPIs

 Dynamic measures adjust calculations based on user input or slicers.

DAX

Selected Metric = SWITCH(

TRUE(),

[Metric] = "Sales", SUM(Sales[Amount]),


[Metric] = "Profit", SUM(Sales[Profit]),

 KPI (Key Performance Indicators) are created using DAX to compare actual values
against targets.

DAX Debugging and Optimization

1. Debugging DAX

 Use the Performance Analyzer in Power BI to identify slow measures or visuals.


 Break down complex DAX formulas into smaller parts for testing.
 Use the Evaluate function in DAX Studio for step-by-step analysis.
2. Optimization Techniques

 Avoid Calculated Columns: Use measures instead, as they are calculated


dynamically and do not consume storage.
 Minimize Iterative Functions: Functions like SUMX or FILTER should be
used judiciously.
 Reduce Cardinality: Avoid high cardinality columns (e.g., unique IDs) in
visuals.
 Pre-aggregate Data: Summarize data in the source system to reduce
processing in Power BI.
 Leverage Variables: Use variables to store intermediate calculations for
reuse and readability.
DAX

Profit Margin =

VAR TotalSales = SUM(Sales[Amount])

VAR TotalCost = SUM(Sales[Cost])

RETURN

(TotalSales - TotalCost) / TotalSales

5.Power BI: Visualization Notes

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

Power BI provides a range of standard visualizations to analyse and present data.

Bar Charts
 Represent data using rectangular bars.

 Types:

 Clustered Bar Chart: Compares values across categories.


 Stacked Bar Chart: Shows the contribution of each category to a total.

Line Charts

 Show trends over time by connecting data points with lines.


 Useful for time series analysis (e.g., monthly sales trends).
Pie Charts

 Represent proportions as slices of a circle.


 Suitable for showing percentages or parts of a whole.

Tables and Matrices

 Table: Displays raw data in rows and columns.


 Matrix: A pivot-table-like visualization for multi-dimensional data.

2. Advanced Visuals

Maps

 Filled Maps: Display geographical regions with color-coded values.


 Bubble Maps: Show data points as bubbles on a map.

Scatter Plots

 Represent relationships between two numeric variables.


 Useful for identifying patterns, clusters, or outliers.
KPI Cards

 Display key performance indicators (KPIs) with progress metrics.

3. Custom Visuals

Installing and Using Visuals from AppSource

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.

Building Custom Visuals Python

 Power BI allows integration Python to create custom visuals.

 Steps:

 Enable R or Python scripting in Power BI.


 Write a script to generate the desired visualization.
Example:

Python
import matplotlib.pyplot as plt

import seaborn as sns

# Assuming 'data' is a Pandas DataFrame with columns 'x' and 'y'

sns.scatterplot(data=data, x='x', y='y')

# Show the plot

plt.show()

4. Best Practices for Visual Design

Color Theory

 Use a consistent and accessible color scheme.


 Avoid overusing bright or clashing colors.

Layout and Storytelling

 Arrange visuals in a logical order to guide the user through a narrative.


 Place KPIs at the top and detailed breakdowns below.

Use of Slicers, Filters, and Bookmarks

 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

 Enables navigation to a detailed report by selecting data in a visual.


 Example: Clicking on a region in a bar chart to view regional sales details.
Cross-Filtering

 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

 Provide additional information when hovering over a data point.


 Example: Hovering over a bar to see exact sales figures.

6. Conditional Formatting and Dynamic Titles

Conditional Formatting

 Apply color rules to highlight data trends or anomalies.

Example:
 Green for positive growth, red for negative growth.
Dynamic Titles

 Titles that update based on user selections or filters.

Example:

DAX

SelectedRegionTitle = "Sales in " & SELECTEDVALUE(Region[RegionName])

You might also like