Counting occurences of values within a continuous range specified by limits
I have two tables. The first table 'units' represents different models of electronic hardware units. The second 'radios' represents radios that are part of units. A given unit may have one or more radios. One radio is associated with at most one unit. Each radio is characterized by a frequency range at which it emits electromagnetic radiation. The range is fully specified by a minimum and maximum frequency, which are real numbers.
I want to graph the number of units sold that emit for given frequencies. I managed to create a measure when I specify one frequency value:
Note that there is a parenthesis missing so that the code that works is:
Num units at freq =
var currentFreq = SELECTEDVALUE( 'Desired freq'[freq])
return CALCULATE( SUMX(radios, RELATED(units[units_sold_num])),
radios[frequency_max] >= currentFreq && radios[frequency_min] <= currentFreq
However, this would sum [units_sold_num] as many times as there are radios satisfying the criteria, whereas we do not want to count units multiple times for a currentFreq value. It's not obvious to me how to avoid this.