I have created the measure below to count equipment events over time.
It is possible for users to accidentally enter Events with dates before or after Equipment Commission and Decommission dates. In these instances, we need to exclude these Events. Event Date has a relationship with DateTable[Date].
It should be noted that each Equipment is assigned to a Facility. Prior to adding RELATEDTABLE, I could not use Facility as a category to get the result I need within visuals.
This measure works exactly as I require. However, I feel like it is terribly slow and inefficient.
Event Count =
CALCULATE (
COUNTROWS ( 'Events' ),
FILTER (
RELATEDTABLE( 'Equipment' ),
('Equipment'[CommissionDate] <= MAX ( DateTable[Date])
|| ISBLANK ( 'Equipment'[CommissionDate]))
&& ('Equipment'[DecommissionDate] >= MAX ( 'DateTable'[Date] )
|| ISBLANK ( 'Equipment'[DecommissionDate] ))
)
)
Any thoughts on improvements would be greatly beneficial.