# Dynamically Calculating The Previous Highest Result Using DAX Functions

DAX functions greatly expand dynamic calculations. They also broaden the other important capabilities in Power BI.  In this tutorial, we’ll discuss how you can dynamically calculate the previous highest result in Power BI. We’ll also be learning the right combination of formula and techniques for this particular calculation. You may watch the full video of this tutorial at the bottom of this blog.

By doing a dynamic calculation, we can run the calculation of a selected data set, while their previous highest result continuously updates and is being displayed visually.

I’ll be showing you how you can actually do this. The formula for this does not need to be too complex at all. It just requires a really good understanding of iterating functions to make it work.

## Getting Data Into A Table

Let’s duplicate our current visualization here and we’ll have a look at it as a table.

Always make sure you get your data into a table. This allows you to actually have a look at the results.

Before anything else, let’s change the format of the Date column into this format that I usually prefer.

## Combination Of DAX Functions For Previous High Result Calculation

Here is the combination of DAX functions that we will use to calculate the previous highest result in your Power BI reports.

Take note that it is essential to get inside tables to fully understand what data you’re looking at.

Basically, we need to look back across every previous day. Then, identify what the maximum revenue date on any day was. Moreover, as we go down the list, the dates that we need to work through are going to be larger and larger.

This is because we’ve got to historically look back over every previous day for every single result in our table. That is exactly what I have done in this formula.

## Using The MAXX DAX Function

In this formula, I used an iterating function called MAXX.

This allows you to create the previously mentioned iteration. This iteration is essential for calculating the previous highest result.

All we need to do is to place the revised virtual table for every single result that we need to iterate through using this logic.

Now, let’s try to work through an example for this calculation.

## Using FILTER And ALLSELECTED DAX Functions

Let’s have a look at 6th of January, 2018 which will serve as our current date.

This FILTER function within the formula will look back through every single date in the currently applied context or filter. This is made possible with the help of the ALLSELECTED function.

The ALLSELECTED function only looks at dates within the current context (in this case, 2018).

If we used the ALL function instead of ALLSELECTED, it would look back through every single date from the beginning of time.

## Evaluating Through Every Single Dates

After looking through the dates in the current context, it’s going to iterate through every single day within your table. Then, it’s going to filter out the days that are less than or equal to the current date in the particular context.

The current date is calculated using the MAX function.

In this context, the current date is the 6th of January. Therefore, if the date is less than or equal to the current date, that will equate to TRUE.

Furthermore, that is also going to be the virtual table of dates that we will have within this iterating function.

Additionally, we will iterate through only those particular dates. Then, we will identify the maximum revenue day (Total Revenue).

Consequently, that’s what it does to every single row in this table. Every single calculation is done exactly the same.

Obviously, this virtual table gets bigger and bigger as you move down the list. And when you set it up exactly like this, it becomes completely dynamic.

By doing that, you can select anything from the filters. You can even change the date and time frame as well.

In addition, you’ll see that the Previous High visualization continuously reevaluates to calculate the highest value on an ongoing basis.

In other words, it’s like a live MAX value. If we add more and more filters, we’d still get updated results.

This formula is obviously not too complex. However, it can produce and add a few insights for your reports. Once you get the correct calculations into the table, you can finally change it into a Line and stacked column chart.

## Conclusion

To sum up, the key for this particular insight is to make sure you understand iterating functions. It will also allow you to place virtual tables inside them as well.

This highlights the outstanding capabilities of Power BI in terms of creating simple formulas, and the dynamic results that you can easily get.

This is quite a unique calculation which holds a lot of value. It can also add a little bit of color to your insights.

Good luck in trying to implement this into your own models.

For more information on how you can combine important DAX functions to find complex and valuable data insights in Power BI, you can check out this module at Enterprise DNA Online.

Sam

Sam McKay, CFA
Sam is Enterprise DNA's CEO & Founder. He helps individuals and organizations develop data driven cultures and create enterprise value by delivering business intelligence training and education.

## Matrix Visualization In Power BI

I will show you formatting tricks on how to put think borders on matrix visualizations in Power BI....

## Power Query Each Expression: An Introduction

Power Query is a data transformation and manipulation tool that's available in Microsoft Excel and...

## VertiPaq Analyzer In DAX Studio | Power BI Tutorial

This tutorial will showcase the VertiPaq Analyzer Metrics in DAX Studio and how it helps in optimizing...

## Convert The Date Table Function Into A Table Query In Power BI

I'm going to show you how to turn an M code for a date table into a table query. You may watch the full...

## Creating Power BI Tables By Using UNION & ROW Function

I'm going to show you how you can create Power BI tables using a formula that combines the UNION...

## Time Comparisons In Power BI: This Year vs Last Year

I want to go over how you can easily do time comparisons in Power BI and specifically calculate this...

## Power BI Slicers Tutorial: Counting Selections Correctly

In today's tutorial, I'm going to work through a subtle issue with Power BI slicers that can trip you...

## Rule Of Thirds: The Composition Rules

When it comes to presenting the story, we need to start with the layout. This is where the rule of...

## Tips For A Successful Power BI Implementation

We'll continue our series on Power BI project planning and implementation. This time around, we'll be...

## 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...

## Predicting When Will Your Customers Purchase Next w/Power BI

What if you could know when your customers are likely to make their next purchase using predictive...

## Power BI Challenge 14 – Emergency Services Analytics

We've been very busy here at Enterprise DNA as we continue to level up our content so that all of you...