Hiring Partners
Segilola Resources Operating LimitedTaviatech TechnologiesFCMBMTN NigeriaAdvans La Fayette Microfinance BankAboki AfricaFirst Bank of NigeriaOPay
โ† Introduction to Power BI ยท Lesson 8 of 9

Module Seven

๐Ÿ“– Every lesson in this course is free to read right here, no account needed. Create a free account to track your progress, take the exam, and earn your certificate.
8
Module 7: Introduction to DAX and Data Analysis in Power BI Module 7: Introduction to DAX and Data Analysis

Module 7: Introduction to DAX and Data Analysis in Power BI

Introduction

Imagine that you are a data analyst working for a supermarket in Ibadan.

Your manager gives you a sales report and asks you some questions:

  • What is the total amount of money the supermarket made?
  • What is the average sales amount?
  • Which product generated the highest sales?
  • How many products were sold?
  • What is the total profit?

Power BI can help you answer these questions using a special formula language called DAX.

DAX allows you to create calculations and perform deeper analysis on your data.

In this module, you will learn the basics of DAX and how to use simple formulas to calculate useful information.

What you will learn:
  • What DAX means.
  • Why DAX is important in Power BI.
  • How to create simple DAX formulas.
  • How to calculate totals and averages.
  • What calculated columns are.
  • What measures are.
  • The difference between calculated columns and measures.
  • How to use DAX to analyse business information.

1. What Is DAX?

DAX stands for Data Analysis Expressions.

It is a formula language used in Power BI, Excel Power Pivot and Analysis Services to perform calculations and analyse data.

You can think of DAX as a way of giving Power BI instructions about what to calculate.

For example, you can tell Power BI to:

  • Add all sales amounts together.
  • Calculate the average examination score.
  • Count the number of customers.
  • Find the highest sales amount.
  • Calculate profit from sales and expenses.

Instead of calculating everything manually, you can write a DAX formula and let Power BI perform the calculation.

Simple explanation:

DAX is like a calculator inside Power BI. You write formulas, and Power BI uses your data to produce answers.

2. Why Is DAX Important?

Power BI can create charts directly from imported data. However, sometimes you need to perform calculations that are not already available in your tables.

This is where DAX becomes useful.

DAX helps you:

  • Calculate total sales.
  • Find average scores.
  • Calculate profit and expenses.
  • Count customers and transactions.
  • Compare current and previous periods.
  • Calculate percentages.
  • Create custom business calculations.

Example

A supermarket has the following sales records:

Product Sales Amount
Rice 500000
Beans 300000
Milk 200000
Bread 150000

The manager wants to know the total sales.

You can write a DAX formula to add all the sales amounts together.

Total Sales = SUM(Sales[Sales Amount])

The answer is โ‚ฆ1,150,000.

3. Understanding DAX Formulas

A DAX formula is an instruction that tells Power BI what calculation to perform.

Most DAX formulas contain a name, an equals sign and an expression.

Example:

Total Sales = SUM(Sales[Sales Amount])

Let's understand each part:

  • Total Sales: The name of the calculation.
  • =: Tells Power BI that a formula follows.
  • SUM: A DAX function that adds values together.
  • Sales: The name of the table.
  • Sales Amount: The name of the column containing the numbers.

The table and column reference is written as Sales[Sales Amount].

Remember: In DAX, square brackets are used to refer to columns and measures. A table name followed by a column name in square brackets identifies a column in that table.

4. Understanding Common DAX Functions

DAX has many functions. A function is a ready-made instruction that performs a particular calculation.

Let's explore some beginner-friendly functions.

A. SUM Function

The SUM function adds all the numbers in a column.

Example:

Total Sales = SUM(Sales[Sales Amount])

If your sales amounts are 500,000, 300,000 and 200,000, the result will be 1,000,000.

B. AVERAGE Function

The AVERAGE function calculates the mean of a group of numbers.

Example:

Average Score = AVERAGE(Results[Score])

If three students score 70, 80 and 90, the average is 80.

C. COUNT Function

The COUNT function counts the number of non-blank values in a column containing numbers.

Example:

Number of Scores = COUNT(Results[Score])

If the Score column contains five numeric values, the result will be 5.

D. COUNTA Function

The COUNTA function counts non-blank values in a column. It can count text and numbers.

Example:

Number of Customers = COUNTA(Customers[Customer Name])

This calculates how many customer-name entries are not blank.

E. MAX Function

The MAX function finds the highest value in a column.

Example:

Highest Score = MAX(Results[Score])

If the scores are 60, 75, 90 and 85, the result will be 90.

F. MIN Function

The MIN function finds the smallest value in a column.

Example:

Lowest Score = MIN(Results[Score])

If the scores are 60, 75, 90 and 85, the result will be 60.

G. DISTINCTCOUNT Function

DISTINCTCOUNT counts the number of different values in a column.

Example:

Unique Customers = DISTINCTCOUNT(Sales[Customer ID])

If the same customer appears in several sales records, the customer is counted only once.

Function What It Does
SUM Adds numbers together.
AVERAGE Calculates the average.
COUNT Counts non-blank numeric values.
COUNTA Counts non-blank values.
MAX Finds the highest value.
MIN Finds the lowest value.
DISTINCTCOUNT Counts unique values.

5. How to Create a Measure in Power BI

A measure is a DAX calculation that produces a result when Power BI needs it in a report.

Measures are commonly used to calculate totals, averages, percentages and other summaries.

Example: Create a Total Sales Measure

Imagine that you have imported a Sales table containing a Sales Amount column.

Follow these steps:

  1. Open Power BI Desktop.
  2. Open your sales report.
  3. Find the Sales table in the Data pane.
  4. Right-click the Sales table.
  5. Select New measure.
  6. A formula bar will appear.
  7. Enter the following formula:
Total Sales = SUM(Sales[Sales Amount])
  1. Press Enter on your keyboard.
  2. Your new measure will appear under the Sales table.

You can now drag the Total Sales measure onto a Card visual to display the total sales amount.

Important: A measure is usually calculated when it is used in a visual. Its result can change depending on filters and the data being displayed.

6. What Is a Calculated Column?

A calculated column is a new column created using a DAX formula.

It calculates a value for each row in a table.

Imagine that a supermarket has a table containing product sales:

Product Sales Amount Cost
Rice 500000 350000
Beans 300000 210000
Milk 200000 140000

The manager wants to calculate the profit for each product.

You can create a calculated column using:

Profit = Sales[Sales Amount] - Sales[Cost]

Power BI calculates the profit for every row.

Product Sales Amount Cost Profit
Rice 500000 350000 150000
Beans 300000 210000 90000
Milk 200000 140000 60000

How to Create a Calculated Column

  1. Open Power BI Desktop.
  2. Select the Sales table.
  3. Go to the Table tools or Modeling ribbon.
  4. Select New column.
  5. Enter the formula:
Profit = Sales[Sales Amount] - Sales[Cost]
  1. Press Enter.
  2. Power BI will create a new Profit column.

7. Difference Between Measures and Calculated Columns

Measures and calculated columns are both created using DAX, but they perform different jobs.

Measure Calculated Column
Calculates a result when used in a report. Calculates a value for each row.
Responds to report filters and selections. Values are calculated during data refresh or model processing.
Commonly used for totals and averages. Commonly used to create new row-level information.
Does not store a separate value for every row. Stores calculated values in the model.

Simple Example

Suppose you want to calculate the total profit for a supermarket.

A measure could be:

Total Profit = SUM(Sales[Sales Amount]) - SUM(Sales[Cost])

Suppose you want to calculate the profit for each individual sales record.

A calculated column could be:

Profit = Sales[Sales Amount] - Sales[Cost]
Easy way to remember:
  • Measure: Answers a question about a group of records.
  • Calculated column: Creates a new value for each row.

8. Understanding Basic DAX Operators

DAX uses mathematical operators to perform calculations.

Operator Meaning Example
+ Addition 10 + 5 = 15
- Subtraction 10 - 5 = 5
* Multiplication 10 * 5 = 50
/ Division 10 / 5 = 2
= Equal to or formula assignment Profit = 100 - 40
> Greater than Score > 50
< Less than Score < 50

Example: Calculate Profit

If a supermarket sells a product for โ‚ฆ50,000 and the cost is โ‚ฆ30,000:

Profit = Sales[Sales Amount] - Sales[Cost]

The profit is โ‚ฆ20,000.

Example: Calculate Profit Percentage

You can calculate profit as a percentage of sales using:

Profit Percentage =
DIVIDE([Total Profit], [Total Sales], 0)

Format the measure as a percentage in Power BI.

The DIVIDE function is useful because it handles division by zero more safely than the ordinary division operator.

9. Understanding the IF Function

The IF function allows Power BI to make a decision based on a condition.

It works like asking a question:

  • If the condition is true, show one result.
  • If the condition is false, show another result.

Example: Student Examination Results

Imagine that a school wants to classify students according to their examination scores.

Students who score 50 or above will receive a Pass result. Students who score below 50 will receive a Fail result.

You can create a calculated column:

Result Status =
IF(Results[Score] >= 50, "Pass", "Fail")

Power BI checks each student's score and displays the appropriate result.

Student Score Result Status
Ada 85 Pass
John 45 Fail
Mary 70 Pass

10. Understanding CALCULATE

CALCULATE is one of the most important DAX functions.

It evaluates an expression after changing or applying filter conditions.

Let's use a supermarket example.

Your sales table contains different products. Your manager wants to know the total sales made from rice only.

You can write:

Rice Sales =
CALCULATE(
    SUM(Sales[Sales Amount]),
    Sales[Product] = "Rice"
)

Power BI calculates the total sales where the product is Rice.

CALCULATE is especially useful when you want a measure to answer a specific business question.

Beginner tip: CALCULATE changes the filter context used for a calculation. You do not need to master every detail now. Start by understanding that it can calculate a result for selected conditions.

11. Understanding Filter Context

Filter context means the filters and selections that affect a calculation in Power BI.

For example, imagine that your sales report contains records for January, February and March.

If you select January using a slicer, a Total Sales measure can show January's sales only.

If you select February, the same measure can show February's sales.

The measure does not need to be rewritten every time you select a different month.

Example

Month Sales
January 500000
February 300000
March 400000

Create this measure:

Total Sales = SUM(Sales[Sales Amount])

When you place Month and Total Sales in a chart, Power BI can calculate sales separately for each month.

When you select January in a slicer, the measure can display โ‚ฆ500,000, assuming the slicer is connected to the sales data correctly.

12. Practical Activity: Create a Sales Analysis Using DAX

Your Mission

You are working as a junior data analyst for a supermarket in Ibadan.

Your manager wants you to calculate total sales, total costs and profit.

Use this data:

Product Sales Amount Cost Quantity
Rice 500000 350000 50
Beans 300000 210000 30
Milk 200000 140000 40
Bread 150000 90000 75
Cooking Oil 250000 180000 25

Step 1: Import the Data

  1. Enter the information into Excel.
  2. Save the workbook as SalesAnalysis.xlsx.
  3. Open Power BI Desktop.
  4. Import the Excel workbook.

Step 2: Create a Total Sales Measure

Use this formula:

Total Sales = SUM(Sales[Sales Amount])
    

Step 3: Create a Total Cost Measure

Total Cost = SUM(Sales[Cost])
    

Step 4: Create a Total Profit Measure

Total Profit = [Total Sales] - [Total Cost]
    

Step 5: Calculate Total Quantity Sold

Total Quantity = SUM(Sales[Quantity])
    

Step 6: Calculate Average Sales

Average Sales = AVERAGE(Sales[Sales Amount])
    

Step 7: Create a Profit Percentage Measure

Profit Percentage =
DIVIDE([Total Profit], [Total Sales], 0)
    

Format Profit Percentage as a percentage.

Step 8: Create Your Report

  1. Add a Card showing Total Sales.
  2. Add a Card showing Total Cost.
  3. Add a Card showing Total Profit.
  4. Add a Card showing Total Quantity.
  5. Create a bar chart showing profit by product.
  6. Create a column chart showing sales by product.
  7. Give each visual a clear title.
  8. Save your work as SalesAnalysisReport.pbix.

Questions to Answer

  1. What is the total sales amount?
  2. What is the total cost?
  3. What is the total profit?
  4. Which product generated the highest profit?
  5. Which product had the highest quantity sold?
  6. Why is a measure useful when calculating total sales?

13. Common DAX Mistakes Beginners Should Avoid

1. Misspelling Table or Column Names

Always use the correct table and column names in your formulas.

2. Using the Wrong Data Type

Make sure that columns used for mathematical calculations contain suitable numeric data.

3. Confusing Measures with Calculated Columns

Remember that measures calculate results based on the current report context, while calculated columns create values for individual rows.

4. Forgetting Brackets

Column references in DAX use square brackets.

Correct example:

SUM(Sales[Sales Amount])

5. Dividing by Zero

Use DIVIDE when you need safer division.

Profit Percentage = DIVIDE([Total Profit], [Total Sales], 0)

6. Writing Formulas Without Checking the Result

Always compare your calculations with the original data to make sure your results are correct.

14. Important Terms to Remember

Term Meaning
DAX Data Analysis Expressions, the formula language used in Power BI.
Function A ready-made instruction that performs a calculation.
Measure A calculation evaluated in the current report context.
Calculated Column A new column calculated for each row using a formula.
SUM Adds values together.
AVERAGE Calculates the mean of a group of numbers.
COUNT Counts non-blank numeric values.
MAX Finds the highest value.
MIN Finds the smallest value.
IF Returns different results depending on a condition.
CALCULATE Evaluates an expression using modified filter conditions.
Filter Context The filters and selections that affect a calculation.

15. Module 7 Assessment: Test Your Knowledge

1. What does DAX stand for?

  1. Data Application Exchange
  2. Data Analysis Expressions
  3. Digital Analysis Extension
  4. Database Access Example

2. What is DAX used for in Power BI?

  1. Creating computer passwords
  2. Writing emails
  3. Performing calculations and analysing data
  4. Installing Windows

3. Which DAX function adds values together?

  1. SUM
  2. MIN
  3. MAX
  4. COUNT

4. Which function calculates the average of numbers?

  1. MAX
  2. SUM
  3. AVERAGE
  4. MIN

5. What is a measure?

  1. A type of computer screen
  2. A DAX calculation evaluated in the current report context
  3. A Power BI theme
  4. A data source

6. What does a calculated column do?

  1. Creates a value for each row
  2. Deletes all columns
  3. Changes the computer language
  4. Creates a website

7. Which DAX function finds the highest value?

  1. MIN
  2. COUNT
  3. MAX
  4. AVERAGE

8. What is the purpose of the IF function?

  1. To create a chart
  2. To make a decision based on a condition
  3. To import Excel files
  4. To delete a table

9. Which function is useful for division that handles division by zero?

  1. SUM
  2. MAX
  3. DIVIDE
  4. COUNTA

10. What does CALCULATE do?

  1. Changes the computer screen
  2. Deletes a report
  3. Evaluates an expression with modified filter conditions
  4. Installs Power BI

Assessment Answer Key

  1. B - Data Analysis Expressions.
  2. C - Performing calculations and analysing data.
  3. A - SUM.
  4. C - AVERAGE.
  5. B - A DAX calculation evaluated in the current report context.
  6. A - Creates a value for each row.
  7. C - MAX.
  8. B - To make a decision based on a condition.
  9. C - DIVIDE.
  10. C - Evaluates an expression with modified filter conditions.

16. Module Summary

In this module, you learned how to use DAX to perform calculations in Power BI.

You discovered that:

  • DAX means Data Analysis Expressions.
  • DAX helps you calculate and analyse information.
  • SUM adds numbers together.
  • AVERAGE calculates the mean.
  • COUNT and COUNTA count values.
  • MAX and MIN find the highest and lowest values.
  • Measures calculate results based on report context.
  • Calculated columns create values for individual rows.
  • IF helps you make decisions using conditions.
  • CALCULATE evaluates expressions using modified filters.
Congratulations!

You have completed Module 7 of Introduction to Power BI.

You can now create basic DAX formulas to answer business questions and perform calculations.

Coming Up in Module 8

Building Interactive Reports and Dashboards

In the next module, you will learn how to combine charts, cards, slicers and other visuals to create reports that people can explore.

You will discover:

  • How to design an interactive report.
  • How to use slicers and filters.
  • How to create drill-through pages.
  • How to use buttons and bookmarks.
  • How to improve report design.
  • How to make reports easier to understand.

Get ready to build reports that allow people to explore their data!

๐Ÿ† Get Certified

๐Ÿ”’

Earn this certificate

Every lesson is already free to read. Sign up, finish the lessons, pass the exam (โ‚ฆ2,000 or 20,000 coins), and get a verified certificate with your name on it.

๐ŸŽ“ Sign Up to Get Certified
๐Ÿ› ๏ธ Practice Tools
Hands-on simulators & labs - subscription required.
โ†’
๐ŸŽฏ Internship Tasks
Real-world tasks to build your portfolio - unlock them with a subscription.
โ†’