# CALCULATE Function – How It Can Affect Your Calculations On Power BI

In this tutorial, I want to show you what the CALCULATE function can do through a few examples.

CALCULATE is one of the most frequently used functions in Power BI. It dictates the context being applied to any measure and removes any existing filters in place.

## Using CALCULATE Function For Total Sales

To truly understand the impact that CALCULATE has, it’s important to remember that any result within Power BI is computed row per row. It all depends on the context given.

Let’s take a look at this sample data. For this row, the measure gives us a result of 108,466.30 when the CALCULATE function was used. This CALCULATE column basically shows the numbers from the same date last year through the use of the SAMEPERIODLASTYEAR function.

That result is based on the initial context applied, which is the date. For this specific row, the date given is August 14, 2020.

That date is also the initial context for the Total Sales measure, which gives us 220,148.60 in that row based on the present time.

But what if within this particular context, I also want to show what we made from a sales perspective but from a different time? This is where CALCULATE becomes even more useful.

## Using The CALCULATE Function With DATEADD

CALCULATE is currently allowing me to compare the Total Sales for the current time period and the sales from last year on the same day. But this comparison doesn’t necessarily have to be done on an annual basis. We can do day-to-day comparison, and even monthly and quarterly calculations as well.

Before we do that, let’s take a look at the original measure.

Using CALCULATE, I referenced the Total Sales and used the function SAMEPERIODLASTYEAR. This function allows me to jump exactly one year before the current date.

Of course, that sets a restriction on my calculation because it won’t allow me to go beyond the one-year period. So I’ll create a new measure that will let me to do that.

I’m going to start the measure the same way the original measure was made. I’m going to use CALCULATE and reference Total Sales.

Then, I’m going to use the time intelligence function DATEADD and set it to go back for just one quarter.

Once I add that into my table, you’ll see that I now have data that shows the numbers from one quarter ago.

That’s the advantage of using DATEADD in your measures. It allows you to set any timeframe, as opposed to SAMEPERIODLASTYEAR, which only counts exactly one year prior to the current date.

This time, let me change that measure and set the time back to only one day, instead of one quarter.

As expected, the result I’m getting shows very little difference from the original figure, knowing that only one day has passed.

## Using CALCULATE With The FILTER Function

You can also use CALCULATE with the FILTER function, which allows us to add even more depth to our analysis.

For this example, let’s see what’s going to happen if we FILTER through ALL the Dates.

Next, I’m going to set it to MAX date minus 7, which means one week from the current date.

This gives us a rolling average that looks back at the numbers from a week before, but this time, we’re using FILTER to go back instead of DATEADD.

Again, it all goes back to the context applied. We’re starting off with the initial context, which looks at the current date, then we’re adding more to that context using the CALCULATE function so that we can dictate a new timeframe to look into.

## Conclusion

CALCULATE can definitely give you more range to your reports and allows you to make comparisons on your numbers across different timelines. This is something that you can use on elements other than Total Sales, too.

Hopefully you can start applying this function to your own work soon. Feel free to explore other contexts you can add to your measures using CALCULATE.

All the best,

Sam

***** Related Course Modules *****
Time Intelligence Calculations
Mastering DAX Calculations
Unique Analytical Scenarios

## A Best Practice Implementation Strategy for Power BI

In the past, businesses were run based on what you know and who you know.  That is still true...

## Power BI Trend Analysis: Are Margins Expanding Or Contracting?

In this blog post, I will be diving into a relatively specific insight by conducting a Power BI trend...

## Data Visualization Report Frameworks | Part 2

For today, we'll be continuing the discussion on our enhanced visualization frameworks for Power BI....

## Create A Power BI Sparkline Chart In Report Builder

In this Power BI Report Builder tutorial, youâ€™ll learn how to add a sparkline chart in your paginated...

## Using Iterating Functions SUMX And AVERAGEX In Power BI

One of the most crucial topics for any Power BI beginner to know about is iterating functions. You may...

## PowerApps Documentation: Using MS Docs For Expert Functionalities

Let's talk about Microsoft's PowerApps documentation and what an important resource it can be for users...

## Data Modeling In Power BI: Tips & Best Practices

In this tutorial, you'll learn valuable tips and best practices for data modeling in Power BI. You can...

## Using The Query Builder Feature In DAX Studio

In this tutorial, youâ€™ll learn how to use the Query Builder feature to easily create queries and...

## Time-Related Insights From Your Supply Chain Metric

For this tutorial, I'm going to cover some high-quality time-related insights directly from your supply...

## Create A Multilingual Power BI Report

For today's blog, I want to discuss a not-unusual situation with many of my consulting assignments for...

## CROSSJOIN DAX Function: Server Timings & Query Plan

In this tutorial, youâ€™ll learn how the CROSSJOIN function works in DAX using the Server Timings pane...

## Overview Of The DAX Studio Keyword COLUMN

Another important keyword to learn when using DAX Studio is the COLUMN keyword. In simplest terms, the...