I have a calculated measure in Analysis Services that returns the average daily revenue for a location based on their last three periods. Periods are location defined lengths of time, so one location may close their periods monthly, and another may close their periods quarterly.
To return the average daily revenue I have a factPeriods table that returns the revenue for a period, and the number of days that contribute to the period. The following MDX returns the correct values at the location level, ([Measures].[Days In AR Charges]) / ([Measures].[Days In AR Days]).
The problem is when I roll up to higher levels, say I want to return the average daily revenue by state, the calculation is incorrect because it first aggregates the days contributing to the periods, then divides. I want the averaging to happen at the lowest level first, then to sum the results of the daily average revenue. Here is an example of what happens vs what I would like to happen.
Say I have only two locations, A and B. A closes monthly, B closes quarterly. The results for the last close are:
Location / Revenue / Days contributing to revenue
Location A / $3000 / 30 days Location B / $1800 / 90 days
Location A is generating $100/day revenue, Location B is generating only $20/day in revenue. My total should be $120 day. Instead, it would return $40/day. Here is what happens at the calculation level.
I would like the formula to be in pseudocode SUM(([Measures].[Days In AR Charges]) / ([Measures].[Days In AR Days]))
but it is actually giving me (SUM([Measures].[Days In AR Charges])) / (SUM([Measures].[Days In AR Days]))
Can anyone help me determine the appropriate formula to make this work as desired? It should end up being $100/day + $20/day, not $4800/120 days. I have a suspicious I may need to use descendants but I am not clear on exactly how I would use them, or if that is even the right direction to go.