我知道一些基本的MDX,但似乎无法创建一个计算度量,该度量使用另一个计算度量的日期集合的总和,该度量也是同一日期集合中的另一个度量。
背景是我试图计算简单线性回归系数的最小二乘估计,截距设置为零。我使用这个公式here来做这件事,这很好。然而,我现在想要计算该系数的标准误差,其涉及估计定义的here的残差平方和。
请参阅我在下面编写的代码。 MDX甚至可以实现这一点吗?
With
Member [Measures].[Renewed] As
Sum([Customer Product Status].[Customer Product Status Rollup].&[Renewed], [Measures].[Product Count])
Member [Measures].[Renewed * Product Count] As
[Measures].[Renewed] * [Measures].[Product Count]
Member [Measures].[Product Count * Product Count] As
[Measures].[Product Count] * [Measures].[Product Count]
Member [Measures].[Product Count n] As
Sum([Expiry Date].[Date].Children, 1.0)
Member [Measures].[Product Count Mean] As
Sum([Expiry Date].[Date].Children, [Measures].[Product Count]) / [Measures].[Product Count n]
Member [Measures].[Renewal Rate] As
(Sum([Expiry Date].[Date].Children, [Measures].[Renewed * Product Count]))/
(Sum([Expiry Date].[Date].Children, [Measures].[Product Count * Product Count]))
Member [Measures].[Sum of Squared Residuals] As
Sum([Expiry Date].[Date].Children, ([Measures].[Renewed] - [Measures].[Renewal Rate] * [Measures].[Product Count]) ^ 2.0)
Member [Measures].[Mean of Squared Residuals] As
[Measures].[Sum of Squared Residuals] / ([Measures].[Product Count n] - 1)
Member [Measures].[Renewal Rate Standard Error] As
([Measures].[Mean of Squared Residuals]/Sum([Expiry Date].[Date].Children, [Measures].[Product Count * Product Count])) ^ 0.5
Member [Measures].[Renewal Rate Upper CI] As
[Measures].[Renewal Rate] + 2.0 * [Measures].[Renewal Rate Standard Error]
Member [Measures].[Renewal Rate Lower CI] As
[Measures].[Renewal Rate] - 2.0 * [Measures].[Renewal Rate Standard Error]
Set [Month Name] As
Filter(
[Expiry Date].[Month Name].Children,
StrToMember("[Expiry Date].[Month Of Year Name].&[May]", CONSTRAINED) * StrToMember("[Expiry Date].[Year Name].&[2015]", CONSTRAINED)
)
Set [Historical Months] As
{[Month Name].Item(0).Lag(25) : [Month Name].Item(0).Lag(1)} *
[Expiry Date].[Month Date].Children *
[Expiry Date].[Month of Year Name].Children *
[Expiry Date].[Year Name].Children
Select Non Empty {[Measures].[Renewal Rate],
[Measures].[Renewal Rate Lower CI],
[Measures].[Renewal Rate Upper CI]} On 0,
Non Empty [Historical Months] On 1
From [Product Renewals]
答案 0 :(得分:1)
我通过重写[Measures]。[Squared Residuals之和]测量来实现这个目的。如果你扩展方程并从sum函数中取出[Measures]。[Renewal Rate],那么一切正常。扩展的[Measures]。[Squared Residuals之和]度量现在看起来像这样:
select column1, column2, column3
from mydb
where onecolumn in (number1, number2....number13)
4月的Excel回归结果:
MDX回归结果: