title: MDX - Sum only selected dimension members?
body: <p>I'm quite new to MDX and I'm having a bit of an issue with the aggregation of one of my measures.</p>
  
  <p>In my DSV I have an "Events" table. We track the agents that run these events, and since multiple agents can be involved in running a single event, I have split this out into a separate table of "Agent" with a bridging table in the middle:</p>
  
  <p><a href="http://imgur.com/uAy3moC" rel="nofollow">http://imgur.com/uAy3moC</a></p>
  
  <p>I want to track what is called "Coverage", which is the number of Events held in a particular week and also each agent who ran the event. So if there were 3 events held one week, and one of these events were run by two agents, that would be a coverage of 4.</p>
  
  <p>When I go to analyse the cube, dragging on Week Commencing and my count of Events, I note that it isn't right - It only considers individual events and not the number of agents. Dragging on Agents solves this but I still want to see an overall figure without having to drag on Agents.</p>
  
  <p>So I created a calculated member like so:</p>
  
  <p><code>CREATE MEMBER CURRENTCUBE.[Measures].[Visit Coverage]
  AS 
  IIF([Agents].[Agent].currentmember.parent IS NULL, 
  SUM([Agents].[Agent].[Agent], [Measures].[Events Count]),
  [Measures].[Events Count]);</code></p>
  
  <p>So basically, if all agents are selected (parent is null), sum up all of the events count for each agent, otherwise just give me the events for each individual agent if I'm analysing by agent. This works great...and also works if I want to filter by one particular agent, but then falls over if I try to filter by more than one (but less than all) agents, giving me a null value.</p>
  
  <p>I'm completely stumped on how to solve this one, could anyone help me out?</p>
  
  <p>Chris</p>