Power BI Calculate Function
So, the CALCULATE function evaluates the expression given by the user with all the applied filters. Below is the syntax of the CALCULATE function.
- 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.
You are free to use this image on you website, templates, etc., Please provide us with an attribution linkHow to Provide Attribution?Article Link to be HyperlinkedFor eg:Source: Power BI Calculate (wallstreetmojo.com)
Examples of Dax Calculate Function in Power BI
Below are examples of the DAX CALCULATE function.
Example #1
Below is the data we will 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 directly upload the data table to the Power BI file. We have already uploaded the table to the Power BI Desktop file.
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.
Like this, we can use the CALCULATE function to arrive at different results.
- Right-click on the table, and choose the “New measure” option. Give the name to this measure “Columbia City Sales.” Now, open the CALCULATE function. An expression is the first option. We need to add the “Columbia” city total in this example, so open the SUM function. The “ColumnName” we need to SUM is the “Sales Value” column, so choose the respective column. The “ColumnName” we need to SUM is the “Sales Value” column, so choose the respective column. The table we refer to is the “Sales_Table.” So first, choose the table name. We need to select the “City” column for FilterExpression and give the criteria as “Columbia.” We are done. Close two brackets and press the “Enter” key to get the new measure. Drag the “Columbia City Sales” to “Fields” to see the new measure. Now, this measure only gives the total sales of the city “Columbia.” You can cross-check the “Columbia” city total in Excel as well.
Example #2
Assume for the city “Columbia,” we need only the sales value for the state “South Carolina,” so we need to apply two filters this time.
With the continuation of the previous DAX function, close only one bracket and open another filter function.
Once again, mention the table we are referring to.
This time we need to apply the filter for the column “State,” select the column and give the criteria as “South Carolina.”
The “Sales Value” of the state South Carolina is shown below.
Our new total will be 15,099. It is the sales value for the state “South Carolina” in the city “Columbia.”
Example #3
You want to find the percentage share of each city for the overall sales. It 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. The idea is to get the overall sales total against all the city totals.
So, we need to create one more measure, which is as follows.
Now, insert the “Table” visual first.
Add the “City” name and “Sales Value” columns for this table visual.
As you can see above, we have each city’s total here. The overall sales value is 79,393. Now, drag and drop the new measure column “Overall Sales.”
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.
Drop and drag this new measure to the table to get each city’s “% share.”
Now, we have a “% share” column. Like this, using the CALCULATE DAX function, we can arrive at expressions based on different filters and conditions.
Note: We can also download the Power BI CALCULATE function file from the link below. We can view the final output.
Things to Remember
- The CALCULATE function in Power BI is used to arrive at different results based on conditions.The CALCULATE function is used with other DAX functions in Power BI to get the job done.
Recommended Articles
This article has been a guide to the Power BI CALCULATE function. Here, we discuss using the CALCULATE DAX function in Power BI to apply other functions and practical examples. You may learn more about Power BI from the following articles: –
- SUMMARIZE Function in Power BICreate Matrix Visual in Power BIPower BI RELATEDApply COUNTIF Function in Power BIPower BI Reports Examples