Forum Discussion
Count in SCD2 dimension - optimization
- 5 years ago
Pending the response to my questions above, try this:
Cnt of units V2 := CALCULATE ( SUMX ( VALUES ( 'Units'[unit_id] ), 1 ), VAR minDate_ =MIN ( 'CalendarTable'[Date] ) VAR maxDate_ = MAX ( 'CalendarTable'[Date] ) RETURN FILTER ( ALL ( 'Units'[unit_valid_from], 'Units'[unit_valid_to] ), NOT ( maxDate_ < 'Units'[unit_valid_from] || minDate_ > 'Units'[unit_valid_to] ) ) )Please mark the question solved when done and consider giving a thumbs up if posts are helpful.
Contact me privately for support with any larger-scale BI needs, tutoring, etc.
Cheers
Pending the response to my questions above, try this:
Cnt of units V2 :=
CALCULATE (
SUMX ( VALUES ( 'Units'[unit_id] ), 1 ),
VAR minDate_ =MIN ( 'CalendarTable'[Date] )
VAR maxDate_ = MAX ( 'CalendarTable'[Date] )
RETURN
FILTER (
ALL ( 'Units'[unit_valid_from], 'Units'[unit_valid_to] ),
NOT ( maxDate_ < 'Units'[unit_valid_from]
|| minDate_ > 'Units'[unit_valid_to] )
)
)
Please mark the question solved when done and consider giving a thumbs up if posts are helpful.
Contact me privately for support with any larger-scale BI needs, tutoring, etc.
Cheers
this could be better depending on the data distribution. It leverages the filters being applied to reduce the number of rows to scan
Cnt of units :=
VAR minDate_ =
MIN ( 'CalendarTable'[Date] )
VAR maxDate_ =
MAX ( 'CalendarTable'[Date] )
RETURN
COUNTROWS (
FILTER (
SUMMARIZE (
'Units',
'Units'[unit_id],
'Units'[unit_valid_from],
'Units'[unit_valid_to]
),
NOT ( maxDate_ < 'Units'[unit_valid_from]
|| minDate_ > 'Units'[unit_valid_to] )
)
)
Please mark the question solved when done and consider giving a thumbs up if posts are helpful.
Contact me privately for support with any larger-scale BI needs, tutoring, etc.
Cheers