You are very close to the correct solution. There is not a way that I know if to make that filter happen before the other table calculation. However you can treat the filter as part of the calculation. Its not really filtering at the same time the window_max() is being called it is being used during the calculation then:
IF WINDOW_MAX(IF [Distance]<= [Radius] THEN [Distance] ELSE 0 END)=[Distance]
OR [Origin City]=ATTR([City, State])
All I've changed here is to see if the distance between cities is less than the radius. If it is then use the disance if its greater it makes everything else 0. So the ones within the radius are the only ones every counted.
Neat idea. I like it. Well done.
Thank you, Carl! That is a very clever workaround. That minor change makes it behave exactly as I intended. Thanks again.