Forum Discussion
bikeoholic
5 years agoFrequent Visitor
Count in SCD2 dimension - optimization
Hello PB community! Can anybody please help me with DAX optimization in this scenario: I have Tabular model with 10 dimension tables, no real facts. One of the user request is to count units in ...
- 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
AlB
Community Champion
5 years ago4 secs is still considerable and it's engaging the FE significantly. I'm curious if this version will be faster:
Cnt of units V2_B :=
VAR minDate_ =
MIN ( 'CalendarTable'[Date] )
VAR maxDate_ =
MAX ( 'CalendarTable'[Date] )
RETURN
COUNTROWS (
FILTER (
ALL ( 'Units'[unit_id], 'Units'[unit_valid_from], 'Units'[unit_valid_to] ),
NOT ( maxDate_ < 'Units'[unit_valid_from]
|| minDate_ > 'Units'[unit_valid_to] )
)
)
or this:
Cnt of units V2_C :=
VAR minDate_ =
MIN ( 'CalendarTable'[Date] )
VAR maxDate_ =
MAX ( 'CalendarTable'[Date] )
RETURN
COUNTROWS (
FILTER (
ALL ( 'Units'[unit_id], 'Units'[unit_valid_from], 'Units'[unit_valid_to] ),
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