I had used an alternate solution which is a bit more cumbersome using native OLAP_DML formulae/expression.
The above expression using OLAP Expression Syntax is much better (if it works).
I was not aware of this OLAP expression syntax when i needed to create a kpi for similar requirement.
We had Qty measure and Share along dimension like "Qty - Share at Year level", "Qty - Share of Total Customer".
We needed to get "Qty - Share at Total Customer, Year".
Cube= SALESCUBE
Base Meas = QTY
Step 1) Create Measure which represents "Qty - Total Customer, Year" which will work in any reporting context ...
Note: For time=day1/2/3/ within same year and customer=cust1/2/3/... or Total Customer, the expression result will be constant (result fixed for any dimension members/status along the 2 dimensions - TIME and CUST). Denominator Value changes each year since we have constrainted time dimension to the ancestor of current cell at YR level. If we choose anscestor at TOP level TOTTIME say then the value is fixed for all time dimension members/values.
olap dml expression: QUAL(SALESCUBE_QTY, CUSTOMER limit(CUSTOMER to CUSTOMER_LEVELREL 'TCUST'), TIME limit(limit(TIME to ANCESTORS USING TIME_PARENTREL TIME(TIME TIME)) KEEP TIME_LEVELREL eq 'YR'))
in awxml - this becomes:
ETMeasureColumnName="QTY_TCUST_YR"
Name="QTY_TCUST_YR"
MeasureExpression="OLAP_DML_EXPRESSION('QUAL(SALESCUBE_QTY, CUSTOMER limit(CUSTOMER to CUSTOMER_LEVELREL ''TCUST''), TIME limit(limit(TIME to ANCESTORS USING TIME_PARENTREL TIME(TIME TIME)) KEEP TIME_LEVELREL eq ''YR''))', NUMBER)">
<Classification
Value="AwmDescriptionType=OLAP_DML_CALC"/>
...
<Description
Type="LongDescription"
Language="AMERICAN"
Value="Qty - Total Customer, Year">
Step 2) Define the share measure explicitly since we have already calculated the denominator needed for composite share.
Check for division by 0 error before performing the share calculation explicitly as Numerator= Qty (for current cell/reporting context) and Denominator = Qty - Total Customer, Year (from Step 1)
olap dml expression: if SALESCUBE_QTY_TCUST_YR ne 0 then SALESCUBE_QTY / SALESCUBE_QTY_TCUST_YR else na
in awxml - this becomes:
ETMeasureColumnName="QTY_SHARE_TCUST_YR"
Name="QTY_SHARE_TCUST_YR"
MeasureExpression="OLAP_DML_EXPRESSION('if SALESCUBE_QTY_TCUST_YR ne 0 then SALESCUBE_QTY / SALESCUBE_QTY_TCUST_YR else na', NUMBER)">
<Classification
Value="AwmDescriptionType=OLAP_DML_CALC"/>
...
<Description
Type="LongDescription"
Language="AMERICAN"
Value="Qty - Share of Total Customer, Year">
</Description>
Report needs to use measure QTY_SHARE_TCUST_YR (Qty - Share of Total Customer, Year) defined in Step 2. It may be useful to expose/display intermediate measure QTY_TCUST_YR also so as to make the basis of calculation very clear to the user.
***********
Nick,
If you customize above soln. to use Total Time, Total Prod and Total Organization (along 3 dimensions)... I am sure the fact table has a time dimension which should also be factored in in your calc/defn.
If you have missed out the join to Time dimension from fact in your queries, in olap reporting terms, its similar to Time Dimension selection of Time level = TTIME Total Time (1 node at TOP).
You need:
Step 1) Qty - Total Time, Total Product and Total Org
Step 2) Qty - Share of Total Time, Total Product and Total Org
Then the example you gave should be covered via QTY and QTY_SHARE_TTIME_TPROD_TORG (Step 2)
SUM(quantity)
-------------------------
2875
should be QTY, QTY_SHARE_TTIME_TPROD_TORG (=100%) at Time level = TTIME, Product level = TPROD, Org level = TORG
SUM(quantity)
-------------------------
345 [12% of all products sold]
should be QTY, QTY_SHARE_TTIME_TPROD_TORG (=12% hopefully) at Time level = TTIME, Product level = PROD with report filter on product = 'CX-867054', Org level = TORG
SUM(quantity)
-------------------------
977 [34% of all products sold]
should be QTY, QTY_SHARE_TTIME_TPROD_TORG (=34% hopefully) at Time level = TTIME, Product level = TPROD, Org level = STORE with report filter on store = 'NY_ALBA_013'
SUM(quantity)
-------------------------
88 [3.06% of all products sold]
should be QTY, QTY_SHARE_TTIME_TPROD_TORG (=3.06% hopefully) at Time level = TTIME, Product level = PROD with report filter on product = 'CX-867054', Org level = STORE with report filter on store = 'NY_ALBA_013'
HTH
Shankar