Posts

Showing posts from November, 2020

Power BI DAX: Calculate Running Total for Past N Days, excluding the days that don't match criteria.

Image
Creating a Running Total is pretty simple in DAX, you just take a measure, wrap it inside CALCULATE and then with the help of DATESYTD you can start cumulative total for Dates, Month and one Year ( DATESYTD ) resets at the beginning of new year or any date that you specify in the second argument. Below is an example of a running total using DATESYTD: 1 2 3 4 5 Running Total = CALCULATE ( [Total Sales], DATESYTD ( Dates[ Date ] ) ) One of the problems with DATESYTD is that it does not offer the ability to implement any kind of logic, by logic I mean the ability to filter dates based on the business conditions and then run a cumulative total on it. Fortunately, when you start thinking more in terms of DAX algorithm or the vanilla DAX you start to see that you have a lot of options available, and therefore this post is dedicated to such problems that you have seen or might face in future. Problem Statement: