Forum Discussion
Date DIfference from current selection.
- 2 years ago
To achieve your objective, let's refine your DAX logic to properly calculate the difference and ensure the totals are correctly calculated. We'll create a measure that checks if the completion date falls within the selected date range and then calculate the difference for those vehicles.
Measure to check if the completion date falls within the selected date range:
CompletionInRange =
IF(
COUNTROWS(
FILTER(
ALLSELECTED(vw_vehiclecount),
vw_vehiclecount[Completion Date] >= MIN(vw_vehiclecount[selected_Date]) &&
vw_vehiclecount[Completion Date] <= MAX(vw_vehiclecount[selected_Date])
)
) > 0,
1,
0
)
Measure to calculate the difference in days divided by 30:
Measure =
VAR LastSelectedDate = MAX(vw_vehiclecount[selected_Date])
RETURN
SUMX(
FILTER(
vw_vehiclecount,
vw_vehiclecount[Completion Date] >= MIN(vw_vehiclecount[selected_Date]) &&
vw_vehiclecount[Completion Date] <= LastSelectedDate
),
(DATEDIFF(vw_vehiclecount[Completion Date], LastSelectedDate, DAY) / 30)
)
To achieve your objective, let's refine your DAX logic to properly calculate the difference and ensure the totals are correctly calculated. We'll create a measure that checks if the completion date falls within the selected date range and then calculate the difference for those vehicles.
Measure to check if the completion date falls within the selected date range:
CompletionInRange =
IF(
COUNTROWS(
FILTER(
ALLSELECTED(vw_vehiclecount),
vw_vehiclecount[Completion Date] >= MIN(vw_vehiclecount[selected_Date]) &&
vw_vehiclecount[Completion Date] <= MAX(vw_vehiclecount[selected_Date])
)
) > 0,
1,
0
)
Measure to calculate the difference in days divided by 30:
Measure =
VAR LastSelectedDate = MAX(vw_vehiclecount[selected_Date])
RETURN
SUMX(
FILTER(
vw_vehiclecount,
vw_vehiclecount[Completion Date] >= MIN(vw_vehiclecount[selected_Date]) &&
vw_vehiclecount[Completion Date] <= LastSelectedDate
),
(DATEDIFF(vw_vehiclecount[Completion Date], LastSelectedDate, DAY) / 30)
)