Future-Proof Your Career, Master Data Skills + AI

Blog

Blog

# Time Intelligence DAX Functions In Power BI

by | 7:00 pm EDT | October 08, 2020 | DAX, Power BI

For this tutorial, we’ll branch out to some examples of time intelligence calculations using a combination of DAX functions.

This kind of calculation is useful when you want to compare your business data over a certain period. You can do it by days, months, quarters, or years.

Aside from the CALCULATE function, using other DAX functions can greatly help in building great time-related analysis.

I’ll introduce you to some of the most common DAX functions used for this kind of calculation.

## Using Time Intelligence DAX Functions

In this example, I’ll teach you how to create a new measure to compare the current sales to last year. Specifically, we will compare the sales of a specific day from the previous and current year.

Let’s call this measure as Sales LY and start it off with the CALCULATE function. The CALCULATE function can change the context of any calculation.

Next, we need to put an expression, which in this case, is the Total Sales. Since we need to change the context to compare the sales, we’ll use the SAMEPERIODLASTYEAR function. This function returns a set of dates in the current selection from the previous year.

Lastly, we need to reference the Dates column from the Date table.

In the table, we can already see the current sales data from the Total Sales column. When we bring the Sales LY measure to the table, we’ll be able to see the total sales from last year. The Sales LY table still calculates the total sales, however, the date context is changed to the previous year.

For instance, on the 13th of October, 2018, the Total Sales is \$153,058.20.

If we check the Sales LY data for the 13th of October, 2019, we’ll see that it is also \$153,058.20.

With the help of the CALCULATE function, the formula changes the initial context to look back on the sales of Oct. 13, 2018. This is a simple example of a time intelligence DAX calculation.

## Creating A New Measure Group

If we look at our Key Measures group in the model, you’ll notice that our measures are starting to pile up. Since we’re branching out into a new calculation, it’s best to create a new measure group. This way, we can optimize and clean our Power BI.

To do that, click the Home ribbon, and then click Enter Data.

Since the measures are about time intelligence calculations, we can name the new measure group as Time Comparison. After renaming, click Load.

Then, we can now move the related time intelligence DAX measures into the new table.

Also, we can make the Sales LY measure as the main measure. To do that, click the Modeling ribbon, and then click Home Table. From here, we can change the default home table from Key Measures to Time Comparison.

We can see that the Sales LY measure is now placed under the Time Comparison measure group.

Furthermore, we have to make sure that the Time Comparison table is placed near the Key Measures table.

This is the ideal set up of the data model since the two additional tables are just for organizational purposes. They are not part of the main model structure for data relationships.

## Using Advanced Time Intelligence DAX Functions

We now have the Total Sales and Sales LY data in our table. We can branch out to advanced time intelligence calculations using these core measures and other DAX functions.

In this example, we will calculate for Sales Difference Year on Year. In the formula, we simply have to find the difference between the Total Sales and Sales LY.

To see the results, we just have to bring the Sales Diff. YoY measure into the table. We can also turn this table into a visualization like this.

These are just simple visualizations. However, if we add slicers for months or weeks, the visualization will look more interesting.

In this other example, I’ll teach you another time intelligence calculation using a different DAX function. This time, let’s use the DATEADD function to calculate Sales Last Year.

Using the original formula, we just need to change the SAMEPERIODLASTYEAR to DATEADD. After referencing the Date table, enter -1 as the number of interval.

The DATEADD function is very flexible because we can go by day, month, quarter, or year.

Since we’re going by year, the formula will calculate the total sales from the previous year. Obviously, the results will be the same as before because we just used a different formula.

Lastly, we can simply copy and paste the existing measure and just change the name. For example, from Sales LY to Profits LY. Instead of Total Sales, we’ll reference the Total Profits measure.

That’s how we can see the profits from last year.

We can branch out to more analysis from here, like the current year’s profit. We can even work out the percentage difference year on year.

The key to a great time intelligence calculation is to use a combination of DAX functions.

## Conclusion

These time intelligence examples may be simple, but it’s a great application of all the things that we have discussed so far. We applied the concepts of initial context, iterating functions, aggregating functions, measure branching, and the CALCULATE function.

I hope you’ve learned a lot of techniques and DAX functions. It will be great if you can apply them to your reports as soon as you can.

Sam

## How to Calculate Age in Excel: 5 Best Methods Explained

Looking to calculate age in Excel? Well, you're in the right place. Whether you need to find the age of...

## How to Interpolate in Excel: User Guide With Examples

In data analysis, interpolation plays a crucial role in estimating values that fall between known data...

## Funny ChatGPT Prompts: 20 Hilarious ChatGPT Ideas

In a world where technology continues to amaze us, we have now arrived at the point where we can have a...

## Power BI Slicer Search: User Guide With Examples

Ready to get started with the Power BI slicer? This feature will allow you to filter and slice your...

## How to Move Files in SharePoint: Top 4 Methods Explained

Struggling to move Files in SharePoint? Don't worry, we've all been there. Knowing how to move files...

## How to Return List in Python: 3 Top Methods Explained

The return statement plays a pivotal role in Python. It’s what lets your functions communicate with the...

## How to Create P Value in Excel? A Step-by-Step Guide

Ready to create a P value in Excel? Want to learn how to quickly and efficiently do it? Read on. To...

## How to Strikethrough Text in Excel? Easy Guide + Examples

Want to strikethrough some text in your Excel document but don’t know how? Don’t worry, it's easy, read...

## How To Calculate Z-Scores in Excel? User Guide with Examples

Ready to calculate a z-score in Excel? Awesome. Because we are going to show how to do it quickly and...

## Top 20+ Data Visualization Interview Questions Explained

So, you’re applying for a data visualization or data analytics job? We get it, job interviews can be...

## Top 10 Free Datasets for Statistics Projects

Are you looking for a way to explore and analyze real-world data to enhance your understanding of...

## How to Calculate Standard Error in Excel? Top 3 Methods

The standard error is a key statistical tool that allows you to assess the accuracy and reliability of...