Power BI Calculate

Power BI Calculate Function

CALCULATE is the often used DAX function in Power BI, even though CALCULATE cannot do anything, this function works as a base function to apply other DAX functions in different scenarios. For example, if you want to apply filter and find the average sales for one particular city then we can use the CALCULATE function to apply filter and arrive calculations.

So, the CALCULATE function evaluates the expression given by the user with all the applied filters. Below is the syntax of the CALCULATE function.

Power bi Calculate Syntax
  • Expression: This is nothing but what is the expression we need to perform. For example, if we need to get the sales total.
  • Filter 1: Based on the Expression given, what is the filter we need to apply. For example, to get the Expression result, Filter 1 will be anyone particular city.
  • Filter 2: Based on the Expression given, what is the second set of filters, we need to apply, for example, in the particular city particular PIN Code region.

This article will take you through one of the important and often used DAX functions Calculate in Power BI.

Power-BI-Calculate

You are free to use this image on your website, templates etc, Please provide us with an attribution linkHow to Provide Attribution?Article Link to be Hyperlinked
For eg:
Source: Power BI Calculate (wallstreetmojo.com)

Examples of Dax Calculate Function in Power BI

Below are the examples of the Dax Calculate function.

Example #1

Below is the data we are going to use to demonstrate the CALCULATE function in Power BI. You can use the same data by downloading the excel workbook from the below link.

You can download this Power BI Calculate Excel Template here – Power BI Calculate Excel Template
Power Bi calculate (Excel data)

You can directly upload the data table to the Power BI file. I have already uploaded the table to the Power BI Desktop file.

Power Bi calculate (uploaded data)

Now we will experiment CALCULATE function to arrive at different sets of results.

Arrive at one particular city sales total

For example, assume you need to create a “New Measure,” which gives one particular city total, for example, “Columbia” city.

Steps to use the DAX calculate function in Power BI is as follows.

  1. Right-click on the table, and choose the “New Measure” option.

    Power Bi calculate (new measure).png

  2. Give the name to this measure as “Columbia City Sales.”

    Power Bi calculate (columbia city)

  3. Now open the CALCULATE function.

    Power Bi calculate (Calculate option)

  4. An expression is the first option; in this example, we need to add the “Columbia” city total, so open SUM function.

    Power Bi calculate (Sum)

  5. The Column Name that we need to SUM is “Sales Value Column,” so choose the respective column.

    Power Bi calculate (Sales value)

  6. Now SUM function adds the “sales value” together, but in the Filter argument, we need to mention which city we need to get the sum of sales, so open the FILTER function.

    Power Bi calculate (Filter)

  7. The Table that we refer to is “Sales Table,” so first, choose the table name.

    Power Bi calculate (Sales Table)

  8. For Filter Expression, we need to select the “City” column and give the criteria as “Columbia.”

    Power Bi calculate (Columbia).png

  9. Ok, we are done. Close two brackets and hit the enter key to get the new measure.



    Power Bi calculate (new measure ans)

  10. Drag the Columbia city to fields to see the new measure.

    Power Bi calculate (drag columbia field)

  11. Ok, now this measure gives the total sales of the city “Columbia” only.



    Power Bi calculate (Columbia card)

  12. You can cross-check the “Columbia” city total in Excel as well.



    Power Bi calculate (Pivot table)

Like this, we can use the CALCULATE function to arrive at different kinds of results.

Example #2

For example, assume for the city “Columbia,” we need only the sales value for the state “South Carolina,” so this time, we need to apply two filters.

  • With the continuation of the previous DAX function, close only one bracket and open another filter function.
Power Bi calculate (Another Filter)
  • Once again, mention the table we are referring to.
Power Bi calculate (Filter sales table)
  • This time we need to apply the filter for the column “State” and select the column and give the criteria as “South Carolina.”
South Carolina
  • The sales Value of State South Carolina is shown below.
Power Bi calculate (South Carolina Result)

Our new total will be 15099 i.e., this is the sales value for the state “South Carolina” in the city “Columbia.”

Power Bi calculate (New Total)

Example #3

For example, you want to find the percentage share of each city for the overall sales; this is done by using the below formula.

% Share = City Sale / Overall Sales * 100

But one problem is this is not the excel to use flexibly with cell referencesCell ReferencesCell reference in excel is referring the other cells to a cell to use its values or properties. For instance, if we have data in cell A2 and want to use that in cell A1, use =A2 in cell A1, and this will copy the A2 value in A1.read more; now, the idea is to get the overall sales total against all the city totals.

  • So we need to create one more measure, and that measure is as follows.
Overall sales
  • Now insert “Table” visual first.
Table
  • For this table visual first, add City name and Sales Value columns.
Table Fields
  • As you can see above, we have each city total here, and the overall sales value is 79393. Now drag and drop the new measure column “Overall Sales.”
Drag Overall sales
overall sales 1
  • Now, as you can see against each city, we have an “Overall Sales” value. Now using these two measures, we can create a new measure to get the percentage share. Use the below function to get the new measure.
Percent share Formula
  • Now drag and drop this new measure to the table to get each city % share.
% share result

There you go, we have a % share column. Like this using the CALCULATE DAX function, we can arrive expressions based on different filters and conditions.

Note: Power BI Calculate Function file can also be downloaded from the link below, and the final output can be viewed.

You can download this Power BI Calculate Function Template here – Power BI Calculate Function Template

Things to Remember

  • CALCULATE function in power bi is used to arrive at different results based on conditions.
  • CALCULATE is always used with other DAX functions in power bi to get the job done.

This has been a guide to Power BI Calculate function. Here we discuss how to use Calculate Dax Function in Power BI to apply other functions and practical examples. You may learn more about Power BI from the following articles –

  • 35+ Courses
  • 120+ Hours
  • Full Lifetime Access
  • Certificate of Completion
LEARN MORE >>