0% found this document useful (0 votes)
9 views13 pages

Activity Using The CALCULATE Function

This document provides a lesson on using the CALCULATE function in DAX to modify measures in Power BI for business-specific calculations. It includes a case study for Adventure Works, detailing steps to calculate total revenue, non-US sales, sales of black road bikes, and sales by sales managers using DAX expressions. The conclusion emphasizes the importance of mastering the CALCULATE function to create meaningful data insights and solutions.

Uploaded by

ebadmohdhusain
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)
9 views13 pages

Activity Using The CALCULATE Function

This document provides a lesson on using the CALCULATE function in DAX to modify measures in Power BI for business-specific calculations. It includes a case study for Adventure Works, detailing steps to calculate total revenue, non-US sales, sales of black road bikes, and sales by sales managers using DAX expressions. The conclusion emphasizes the importance of mastering the CALCULATE function to create meaningful data insights and solutions.

Uploaded by

ebadmohdhusain
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/ 13

Activity Using the CALCULATE

function
Introduction
In this lesson, you discovered how to work with DAX and measures. One key area you focused
on was how the CALCULATE function works in DAX to alter the filter context of the
calculations.

In this exercise, you must apply your knowledge of DAX to modify the total revenue measure
using new calculations to answer business-specific questions.

 You’ll walk through the steps to modify or create new measures incorporating the
CALCULATE function in Power BI.
 The goal is to understand how the CALCULATE function behaves to compute the
specific data calculations by changing the context of a DAX expression.

Case study
Adventure Works needs to calculate its total revenue. The company also needs granular
information about the sales performance of its employees and sales of specific products by color,
subcategory, category, and region. You can help Adventure Works to generate these insights
using CALCULATE DAX. This powerful DAX function defines and calculates measures
according to the analytical requirements of the business.

Step 1: Open the Power BI project you created in the


previous exercise.
Access the project from the file path in which it was saved and open it in Power BI.
Step 2: Access the Total revenue measure you
created using the SUMX function and modify it to
calculate non-US revenue.
1. In the case of Adventure Works, you have already created a measure called Total
revenue that uses row context to compute the company's total revenue by iterating
each row of the table. You must now use the CALCULATE function to introduce the new
filter context to the calculation.

1. In the Power BI Data view or Report view, within the Calculations group, select
New Measure and copy and paste the following DAX code in the formula bar to create
a new measure for non-US sales.

1
2
3
4
5
Non-US Sales =
CALCULATE (
[Total Revenue],
FILTER ( Region, Region[Country] <> "United States" )
)
 The expression CALCULATE takes the total revenue measure to compute the total
sales.
 It filters the value based on the country column from the Region table.
 We state that the country should not be equal to the value United States (<> DAX
operator indicates "not equal to.")
Note that the formula uses the previously created Total revenue measure. You can also
modify the existing DAX code to gain the same results as follows:

1
2
3
4
5
Non-US Sales 2 =
CALCULATE (
SUMX ( Sales, Sales[Unit Price] * Sales[Quantity] ),
FILTER ( Region, Region[Country] <> "United States" )
)
 In this DAX expression, instead of using the previously computed Total revenue
measure, an expression to compute the total revenue is added with the SUMX function.
 SUMX calculates the total revenue by multiplying Quantities with Unit price
columns and iterates each table row.
 FILTER narrows down the sales for non-US countries from the Region table.
1. Once executed, the DAX code generates a new measure in the data pane.
2. Format the measure as currency with two decimal places. Select the measure you just
created, navigate to the Formatting group from the Measure tools tab of Power
BI. Select the currency from the format drop-down and enter 2 in the decimal place
section that selects Auto by default.
Step 3: Create a measure to compute the sales of
black road bikes.
1. Adventure Works wants to analyze the sales of black road bikes. You can generate
insights into these sales by modifying your existing total revenue measure or creating a
new one. You must use the total revenue measure within CALCULATE function to
create a new measure. The measure requires that two additional filters be incorporated.
The first is the Road bikes value from the subcategory column, and the second is the
Product color value of Black from the Color column. The DAX code that you must
input into the formula bar to complete this action is as follows:

1
2
3
4
5
6
Black Road Bikes Sales =
CALCULATE (
[Total Revenue],
Products[Subcategory] = "Road Bikes",
Products[Color] = "Black"
)
1. Format the measure as currency with two decimal places, as you did in the previous
step.
Step 4: Create a measure to compute the sales by
Sales Managers.
1. Adventure Works needs to generate insights into the sales performance of its sales
managers. You must help them by calculating the total sales generated by each sales
manager. To calculate this measure, you need to bring the filter of Employee title
from the Salesperson table into the CALCULATE function. You can complete this
action by adding the following DAX expression into the formula bar:

1
2
3
4
5
Sales by Sales Managers =
CALCULATE (
[Total Revenue],
FILTER ( Salesperson, CONTAINSSTRING ( Salesperson[Title], "Manager
" ) )
)
 The CALCULATE function takes the total revenue measure previously created to
compute the sales by sales managers.
 The FILTER function within CALCULATE filters the title column from the
salesperson table.
 The CONTAINSSTRING function evaluates the title column with the defined string, in
this case, its manager. It returns only the titles containing the word Manager.

1. Format the measure as Currency data type with two decimal places, as you did in the
previous step.
Step 5: Save the project.
Save the project as a new project. Ensure to provide an appropriate name and path to the folder
on your local computer.

Conclusion
Congratulations! You have successfully modified and created measures using the CALCULATE
function. This DAX function empowers you to create more meaningful calculations to address
specific analytical needs. You can combine CALCULATE functions with filters and modifiers to
achieve custom analytic goals. Mastering the evaluation context with CALCULATE will help you
build efficient and scalable data solutions for your organization.

You might also like