Forum Discussion
How to count open cases by selected date without generating all intermediate dates?
- 4 months ago
Make sure there is no relationship between your date table and your cases table, then write a measure like
Num open cases = VAR MaxDate = MAX ( 'Date'[Date] ) VAR Result = CALCULATE ( COUNTROWS ( Cases ), Cases[Open Date] <= MaxDate && ( ISBLANK ( Cases[Close Date] ) || Cases[CloseDate] >= MaxDate ) ) RETURN ResultThis assumes that there is 1 row per case in your Cases table. If that's not the case then you will need to do a DISTINCTCOUNT on Case ID, but that could be significantly slower than a COUNTROWS.
The measure should work at any granularity of date. It counts the number of cases where the open date is on or before the end of the period and the close date is either blank ( presumably still open ) or is on or after the end of the period.
- 4 months ago
Use no active relationship between the Date table and the Cases table. Then use the following measure:
Open Cases = VAR _SelectedStart = MIN ( 'Date'[Date] ) VAR _SelectedEnd = MAX ( 'Date'[Date] ) RETURN CALCULATE ( COUNTROWS ( Cases ), FILTER ( ALL ( Cases ), Cases[Open Date] <= _SelectedEnd && ( ISBLANK ( Cases[Close Date] ) || Cases[Close Date] >= _SelectedStart ) ) )
Make sure there is no relationship between your date table and your cases table, then write a measure like
Num open cases =
VAR MaxDate =
MAX ( 'Date'[Date] )
VAR Result =
CALCULATE (
COUNTROWS ( Cases ),
Cases[Open Date] <= MaxDate
&& (
ISBLANK ( Cases[Close Date] ) || Cases[CloseDate] >= MaxDate
)
)
RETURN
Result
This assumes that there is 1 row per case in your Cases table. If that's not the case then you will need to do a DISTINCTCOUNT on Case ID, but that could be significantly slower than a COUNTROWS.
The measure should work at any granularity of date. It counts the number of cases where the open date is on or before the end of the period and the close date is either blank ( presumably still open ) or is on or after the end of the period.