# Using Calculate Function Inside Power BI

For this tutorial, Iâ€™ll cover how the CALCULATE function works and why itâ€™s so crucial in Power BI. I’ll also show you some examples of its application.

You can easily branch out to time intelligence calculations by using the CALCULATE function. Once you apply this technique, you’ll be able to produce high quality insights inside Power BI.

## Using The Calculate Function In Power BI

In this example, I’ll show you how to work out the percentage of the total sales by using the CALCULATE function in Power BI.

Before I start, I’ll show you the existing data in the report. The initial context is the Product Name, and then you can see the Total Sales column.

Since I want to calculate the percentage of total products, I need to work out the product sales first. I’ll create a new measure for All Product Sales, and I’m going to start the formula with the CALCULATE function.

Based on the IntelliSense description above, I’ll have to enter an expression and filter after the function. I’ll start the calculation with Total Sales because I need to calculate all the sales.

I also need to remove any filter or context from the Product Name column. To do that, I’ll add the ALL function and reference the Product table. This is totally fine since the description shows that I can add either a table or column.

Iâ€™ll press Enter to finish the formula, and then bring it into the table.

Now, check out the results in the All Product Sales column. Youâ€™ll see that the result is applied to every single row in the table. The formula literally calculates the total sales. However, I have changed the context in the calculation. In addition to that, I removed the filter from the Products table by using the ALL function.

## Using Measure Branching

In this example, Iâ€™ll show you how to calculate the % of Products Total using the DIVIDE function. Iâ€™ll also apply some measure branching in this example.

First, create a new measure and divide the Total Sales by All Product Sales.

As you can see, I was able to branch out into the % of Products Total using the previous measure that I have created. The initial results are in decimal format so Iâ€™ll quickly convert it to percentage.

I donâ€™t need to keep the intermediary calculations that we used. I can remove them all because the formula will remember everything that has been used in the measures.

I can just copy the existing table and paste it beside the original table, and then turn it into a visualization. But before that, Iâ€™ll delete the Total Sales and All Product Sales columns. Hereâ€™s what it looks like now.

## Conclusion

This is a very simple example of measure branching using the CALCULATE function.

To sum up, the CALCULATE function changes the context of your calculation in Power BI.

When you run time intelligence calculations in Power BI, you also need to change the context. This is how the CALCULATE function is relevant when analyzing and showcasing effective reports.

Sam

## Power BI P&L Statements: Challenges And Solutions

Profit and Loss Statements are often challenging to create in Power BI, especially if you're working...

## How To Install DAX Studio & Tabular Editor In Power BI

In this tutorial, you'll learn how to download and install DAX Studio and Tabular Editor 3 in your...

This tutorial will guide us on how we can download and install R and RStudio which are both free and...

## Launching The Enterprise DNA Membership License

Today we launch a brand new offering from Enterprise DNA.  After a tremendous...

## Iterating Functions In DAX Language – A Detailed Example

For this blog post, I want to dive into iterating functions within the DAX language in Power BI. The...

## Using Power BI DAX Functions To Deal With Products That Have Changing Prices Overtime

In this blog post, we are going to work through an advanced but real-world analysis involving Power BI...

## Power BI Dashboard Designs: Visuals And Effects

An effective dashboard design presents data in a concise, engaging, and powerful way. The presentation...

## DAX Measures In Power BI Using Measure Branching

Build DAX measures using measures. This is what I call measure branching. This technique is one of the...

## Temporal Scale Using Calculated Columns In Power BI

Every so often weâ€™ll be needing the availability of a custom visual of a bar chart or line chart that...

## First N Business Days Revisited – A DAX Coding Language Solution

Let's take another look at the problem discussed in this tutorial, which dynamically compared the first...

## Junk Dimension: What Is It And Why It’s Anything But Junk

Today, I want to talk about a data modeling concept called junk dimension. From its name, you'd think...

## Power BI Slope Chart: An Overview

In this tutorial, we'll be looking at a not-so-common custom visual called the Power BI slope chart....