Quantcast
Channel: SQL Server Analysis Services forum
Viewing all articles
Browse latest Browse all 14337

MDX to calculate an aggregate ratio over a period of varying months

$
0
0

Hi,

I need to calculate a simple ratio in MDX, basically its just measure 1 divided by measure 2 like this:

CREATE MEMBER CURRENTCUBE.[Measures].[Loss Ratio]
AS DIVIDE(Measures.[Incident Total Cost],Measures.[Net Premium Total]),
FORMAT_STRING = "#,##0.00;-#,##0.00;0",
VISIBLE = 1 ,  ASSOCIATED_MEASURE_GROUP = 'Incident';

This calculation works, but what I actually need, is the ratio to be the aggregate result of (year minus 2) + (year minus 1) + (current YTD).

So for example:

In September 2016, it would divide 33 months of aggregated [Incident Total Cost] by 33 months of aggregated [Net Premium Total] (9 months of 2016 + 12 months of 2015 + 12 months of 2014).

So looking at the first 3 months of current year, the result would be different for each month:

Jan: 54% (25 months)

Feb: 45% (26 months)

Mar: 53% (27 months)

Etc...

If this can be achieved without limiting the months in current year to YTD, it would also be fine to just aggregate 36 months at any given point in time.

Please apply the code to my current measure above, as I am not very good at MDX.

Thanks!

Rasmus


Viewing all articles
Browse latest Browse all 14337

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>