BookmarkSubscribeRSS Feed
StephenOverton
Fluorite | Level 6
I'm trying to compute a weighted average in an OLAP cube using a calculated member with some MDX logic but the order of operations is throwing me off and basically forcing a simple average calculation rather than using the weights. This is because the cube is aggregating the measures used in the MDX calc FIRST, then doing the math for the weighted average. I'm looking for a way to force the MDX calculation to do the weighted avg multiplication first, then do the sum aggregation.

Example:
In my dataset I've got mortgage loan-level information with things like current balance, LTV, DTI, etc. I need to create a weighted average of LTV, DTI, or any other variable using the Current Balance as the weight.

So logically the math would be this for Weighted Avg LTV:
1) at the loan level, multiply current balance by LTV to get the weighted LTV
2) sum the weighted LTV across all of the loans (or in the case of OLAP, whatever dimensions are being crossed)
3) sum the current balance (in the case of OLAP, whatever slice)
4) divide step 2 by step 3
5) Viola, weighted average

Any insight is appreciated. The problem is simple, its just figuring out how to control how the calculated member does its math. I could easily do the multiplication in the base dataset and calculate the weighted values but I'd rather do them in the cube.

This is the example define code in the proc OLAP statement along with the measure definitions. The first member define is the problem. I need to force it to NOT do the measure aggregation first. I think I need some function outside of the multiplication.

MEASURE CURR_LOAN_BAL_AMTSUM
STAT = SUM
COLUMN = CURR_LOAN_BAL_AMT
CAPTION = 'Current Loan Balance'
FORMAT = dollar22.2;
MEASURE ORIG_COMB_LTVMAX
STAT = MAX
COLUMN = ORIG_COMB_LTV
CAPTION = 'Combined LTV'
FORMAT = comma14.4;

/* Numerator for weighted average */
DEFINE Member '[Levels_Loan_Detail].[MEASURES].[Wtd CLTV]' AS
'([MEASURES].[CURR_LOAN_BAL_AMTSUM] * [MEASURES].[ORIG_COMB_LTVMAX]), FORMAT_STRING="COMMA15."';

/* Weighted average calculation */
DEFINE Member '[Levels_Loan_Detail].[MEASURES].[Wtd Avg CLTV]' AS
'([MEASURES].[Wtd CLTV] / [MEASURES].[CURR_LOAN_BAL_AMTSUM]), FORMAT_STRING="COMMA15.4"';
2 REPLIES 2
Patrick
Opal | Level 21
Hi

In my experience MDX skills are a rather rare good in the SAS world.

Do you have the "ORION" cubes at hand? And would it be possible to simulate your problem there? That would help a lot in searching for a solution.

Thanks
Patrick

P.S: What Olap Cube Studio version are you using? Message was edited by: Patrick
StephenOverton
Fluorite | Level 6
I figured out the solution using IIF logic in an MDX statement. BUT the hard part with this is you have to detect every possible dimension you want to compute the weighted average for. So I took the easy route and simply put the weights in the source dataset. Worked like a charm after that!

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 2231 views
  • 0 likes
  • 2 in conversation