Power BI is Microsoft's business analytics tool. It combines data preparation, modelling and visualization in one product and is the tool used in the laboratory of this course.
Components of Power BI
Power BI Desktop is the free Windows application in which reports are built. The Power BI Service is the cloud site where reports are published, shared, refreshed on a schedule and combined into dashboards. Power BI Mobile shows reports on phones and tablets. A report is a set of pages of visuals, built from a data model.
The Power BI Workflow
Work in Desktop follows a fixed path. First Get Data from Excel, CSV, databases or web sources. Then Power Query Editor cleans and transforms the data: remove duplicates, fix types, split columns, replace errors, merge or append tables. The cleaned tables are loaded into the data model, where relationships link them. Then measures are written and visuals are added on the report canvas. Finally the report is published to the Service.
The Report View
The Desktop window has the canvas for visuals, the Visualizations pane to choose a chart and set its fields, the Fields (Data) pane listing tables and columns, the Filters pane and the Ribbon. The three views are Report view, Table (Data) view and Model view. Dragging fields onto a visual builds it, and slicers filter the whole page.
DAX Measures
DAX (Data Analysis Expressions) is the formula language of Power BI. A calculated column is computed for each row and stored, while a measure is computed on demand for the current filters. Examples are Total Sales = SUM(Sales[Amount]) and North Sales = CALCULATE(SUM(Sales[Amount]), Sales[Region] = "North"). CALCULATE changes the filter context, so the same measure gives a different value for every bar, slicer selection or row of a table.
Definition: DAX. Data Analysis Expressions, the formula language of Power BI, used to create calculated columns and measures that are evaluated in the current filter context.
Table 2.3: Power BI components
| Component | Where it runs | Purpose |
|---|---|---|
| Power BI Desktop | Windows computer | Build reports and data models |
| Power BI Service | Cloud | Publish, share and schedule refresh |
| Power BI Mobile | Phone, tablet | View reports and dashboards |
| Power Query | Inside Desktop | Clean and transform data |
| DAX | Inside Desktop | Calculated columns and measures |
Example 2.3: Measures in a filter context
Problem: Using the rows (North, 100), (North, 150), (South, 80), (South, 120), (East, 60), find Total Sales, North Sales and North's share of the total as DAX measures would show them.
Solution:
- Total Sales = SUM of Amount = 100 + 150 + 80 + 120 + 60 = 510.
- North Sales = CALCULATE(SUM(Amount), Region = "North") = 100 + 150 = 250.
- Share = North Sales / Total Sales = 250 / 510 = 0.49, or 49 percent.
- On a bar chart by Region the Total Sales measure automatically gives North 250, South 200 and East 60.
Result: Total 510, North 250 and a 49 percent share.
import pandas as pd
sales = pd.DataFrame({
"Region": ["North", "North", "South", "South", "East"],
"Amount": [100, 150, 80, 120, 60]})
total = sales["Amount"].sum()
north = sales.loc[sales["Region"] == "North", "Amount"].sum()
print("Total Sales:", total)
print("North Sales:", north)
print("North share:", round(100 * north / total), "%")
print(sales.groupby("Region")["Amount"].sum().to_string())
Output
Total Sales: 510
North Sales: 250
North share: 49 %
Region
East 60
North 250
South 200
Common mistakes
- Loading unclean data and fixing it with visuals instead of Power Query.
- Using a calculated column where a measure is needed, which increases file size.
- Forgetting that a measure changes with filters and slicers.
- Sharing a report outside the organisation without checking permissions.
Key takeaways
- Desktop builds, Service shares, Mobile views.
- Flow: get data, transform, model, measure and visualize, publish.
- A measure is calculated on demand in the filter context.
- CALCULATE changes the filter context.
Practice questions
- What is Power Query used for?
- What is the difference between a calculated column and a measure?
- Where are Power BI reports shared?
Answers to the practice questions
- Cleaning and transforming data before it is loaded into the model.
- A column is computed per row and stored; a measure is computed on demand for the current filters.
- In the Power BI Service in the cloud.
Sources
- Official BCA syllabus Data Visualization, course code 26BCA404DSE11, Unit II
