Forum Discussion
SOLVED
The behavior you're describing with the `Max_Startdatum` variable becoming empty for months where there's no data is expected in Power BI. Variables in DAX are evaluated within the filter context they are used in. When you apply a filter to a visual, such as a month filter, it impacts the evaluation context for DAX calculations. In this case, when there's no data for a specific month for a given project, the `MAX('Booked_Times'[Startdatum])` calculation returns an empty result, and that propagates to your `Max_Startdatum` variable.
If you want to maintain a constant `Max_Startdatum` for a project even when there's no data for certain months, you can use a technique called "earlier reference" to capture the value once for each project and use that value throughout your calculations. Here's how you can modify your `Max_StartDatum` variable:
```DAX
Max_StartDatum =
VAR ProjectStart = CALCULATE(
MAX('Booked_Times'[Startdatum]),
ALL('Booked_Times'),
VALUES('Booked_Times'[Arbeitsauftrag])
)
RETURN
IF(
ISBLANK(ProjectStart),
EARLIER(ProjectStart), -- Use the previously captured value
ProjectStart -- Use the value for the current project
)
```
In this modified calculation, `EARLIER` captures the `ProjectStart` value for the project when there is data and uses it throughout the calculation, even when there is no data for some months.
This should ensure that `Max_Startdatum` remains constant for each project regardless of whether there is data for all months or not. Please test this modification to see if it meets your requirements for the project's constant start date.
This sounded just like the solution because it is exactly what I want. However, I get an error message saying EARLIER/EARLIEST refer to an earlier row context which doesn't exist. What is that supposed to indicate?