This post is also available in: Deutsch
Sooner or later, every Power BI developer will face the question of how to automatically filter a specific visual or the entire report to today’s date.
This can be done in two ways:
- With a Calculated Column (always works)
- With a measure (works in specific cases)
The approach with a calculated column is much more stable, since measures generally cannot or should not be used as filters. However, if the date exists in the filter context, then this is also possible with a measure, which is why I will present both alternatives.
As just said, filtering by calculated column is the more stable of the two approaches. Here, a new calculated column is created in the date dimension, where it is simply checked whether the date in the particular row matches today’s date:
IsToday = IF( 'Date'[Date] = TODAY(), 1, 0 )
In this way, the content of the new calculated column is always “0”, except for the current date. On this day the line shows a “1”:
The new column can now be used to filter single visuals or the whole report on today’s date. As soon as the day changes, the value in the calculated column also changes and the report adjusts to the new date accordingly:
A less common method is to filter single visuals by measure. Here, the difference between the date and today is evaluated. If this difference is 0, then it is the current day. The formula is:
IsTodayMeasure = DATEDIFF( MAX( 'Date'[Date] ), TODAY(), DAY )
The only disadvantage, the measure requires a filter context. This means it only works in visuals where the date is present in lines or on an axis, for example. As soon as the date is notavailable as a filter context, as in the case of a card visual, the measure cannot be used for filtering.
I have shown the example here:
As just shown, a report can be filtered to today’s date by calculated column with little effort. This method is very stable and has the advantage that the report automatically adjusts to the current date. The possibility per measure exists in certain constellations, if the date column is available in the filter context of the visual. I personally find the option quite elegant, however, it cannot be used generally. Therefore, this is more likely to be classified as a “development feature” to filter a particular visual. However, I would not recommend using this in a productive report.