Forum Discussion
DAX lookupvalue with date condition
To achieve the desired result in Table 2, where you want to set the "child power outage" based on the conditions in Table 1, you need to filter the lookup based on both the meter's "power outage" flag and the selected "measurement date." Unfortunately, you can't directly use `LOOKUPVALUE` for this purpose. Instead, you can create a calculated column in Table 2 using DAX to achieve this. Here's a step-by-step approach to do this:
1. Create a new calculated column in Table 1 to associate each child meter with the measurement date where the parent meter had a power outage. This column will filter based on the "power outage" flag and the selected measurement date.
```DAX
Child Power Outage Date =
VAR SelectedDate = SELECTEDVALUE(Calendar[Date])
RETURN
IF(
CALCULATE(MAX('Table1'[power outage]),
FILTER('Table1', 'Table1'[power outage] = 1 && 'Table1'[date] = SelectedDate)) = 1,
1,
BLANK()
)
```
2. Now, in Table 2, you can create a calculated column "Child Power Outage" that references the "Child Power Outage Date" from Table 1.
```DAX
Child Power Outage = RELATED('Table1'[Child Power Outage Date])
```
This approach ensures that the "Child Power Outage" column in Table 2 is set to 1 only when the "power outage" flag in Table 1 is 1, and the associated measurement date matches the selected date from your calendar table.
Make sure that you have a valid relationship between your tables and that you are using the selected date from your calendar table correctly in the calculations.