# Time Intelligence DAX Functions In 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

## Debugging DAX: Tips and Tools for Troubleshooting Your Formulas

One of the main reasons why businesses all over the world have fallen in love with Power BI is because...

## Practical Application of TREATAS Function in DAX

A hands-on project focused on using the TREATAS function to manipulate and analyze data in DAX.

## MAXX in Power BI – A Detailed Guide

A hands-on guide to implementing data analysis projects using DAX, focused on the MAXX function and its combinations with other essential DAX functions.

## Leveraging the COUNTX Function In Power BI

Learn how to leverage the COUNTX function in DAX for in-depth data analysis. This guide provides step-by-step instructions and practical examples.

## Using the FILTER Function in DAX – A Detailed Guide With Examples

A comprehensive guide to understanding and implementing the FILTER function in DAX, complete with examples and combinations with other functions.

## DATESINPERIOD Function in DAX – A Detailed Guide

Learn how to implement and utilize DAX functions effectively, with a focus on the DATESINPERIOD function.

## Using the DISTINCT Function Effectively in DAX

A systematic exploration of the DAX DISTINCT function to optimize data analytics.

## Guide and Many Examples – ALL Function in DAX

A detailed guide to understanding, implementing, and mastering the DAX ALL function, complemented by practical examples and combinatory techniques.

## Detailed Guide to SWITCH function in DAX

A comprehensive guide to mastering DAX functions in Power BI for conducting advanced data analysis.

## SUMMARIZE Function in DAX – A Deep Dive

A comprehensive guide to using the DAX function SUMMARIZE in Power BI, with detailed explanations and practical examples.

## Your Data Visualization Doesnâ€™t Look Great. What Should You Do?

Data visualization is the key to unlocking the insights hidden within your data. But, what if your...

## Leveraging Power BI for Data-Driven Decisions

In the world of data analytics, thereâ€™s a constant demand for tools that not only help you make sense...