尝试计算 MDX 中的四分位数
Trying to calculate quartiles in MDX
我的数据是这样的:
ID |PersonID |CompanyID |DateID |Throughput |AmountType
33F467AC-F35B-4F24-A05B-FC35CF005981 |7 |53 |200802 |3 |0
04EE0FF0-511D-48F5-AA58-7600B3A69695 |18 |4 |201309 |5 |0
AB058AA5-6228-4E7C-9469-55827A5A34C3 |25 |69 |201108 |266 |0
大约有一百万行。列名 *ID 引用其他表,因此它们可以用作维度。
我有一个 OLAP 多维数据集,其中吞吐量列作为度量,其余列作为维度。
我想计算吞吐量度量的四分位 1 和 3。
我遵循了这个指南:https://electrovoid.wordpress.com/2011/06/24/ssas-quartile/
连同这个 post:Calculating Quartiles in Analysis Services
来自那些我尝试使用此 MDX 查询的人:
WITH
SET selection as ([Dates].[Year].&[2014],[Dates].[Month].&[1])
SET [NonEmptyIds] AS
NonEmpty(
[ThroughputID].[ID].[id]
*[ThroughputID].[ID].[Id].ALLMEMBERS
,
{[Measures].[Throughput]} * [selection]
)
SET [ThroughputData] AS
ORDER
(
[NonEmptyIds],
[Measures].[Throughput],
BASC
)
MEMBER [Measures].[RowCount] AS COUNT (ThroughputData)
MEMBER [Measures].[i25] AS ( .25 * ( [RowCount] - 1 ) ) + 1
MEMBER [Measures].[i25Lo] AS FIX([i25]) - 1
MEMBER [Measures].[i25Rem] AS ([i25] - FIX([i25]))
MEMBER [Measures].[n25Lo] AS (ThroughputData.Item([i25Lo]), [Throughput])
MEMBER [Measures].[n25Hi] AS (ThroughputData.Item([i25Lo] + 1), [Throughput])
MEMBER [Measures].[Quartile1] AS [n25Lo] + ( [i25Rem] * ( [n25Hi] - [Throughput] ))
SELECT
selection ON 0,
[Measures].[Quartile1]
ON 1
FROM (SELECT [Dates].[Y-H-Q-M].MEMBERS ON 0 FROM [Throughput])
但我得到:'Query (6, 7) The ID hierarchy is used more than once in the Crossjoin function.'
我对 OLAP 和 MDX 很陌生。有什么问题吗?我应该如何计算正确的四分位数?
我在某处读到我需要 ID 维度才能在计算四分位数时获得包含所有值而不是聚合值的集合...
罪魁祸首是以下代码:
SET [NonEmptyIds] AS
NonEmpty(
[ThroughputID].[ID].[id]
*[ThroughputID].[ID].[Id].ALLMEMBERS
,
{[Measures].[Throughput]} * [selection]
)
您不能在交叉联接中多次使用同一层次结构。在这里您使用了 [ThroughputID].[ID]
两次。请尝试以下操作:
SET [NonEmptyIds] AS
NonEmpty(
[ThroughputID].[ID].[Id].ALLMEMBERS
,
{[Measures].[Throughput]} * [selection]
)
我的数据是这样的:
ID |PersonID |CompanyID |DateID |Throughput |AmountType
33F467AC-F35B-4F24-A05B-FC35CF005981 |7 |53 |200802 |3 |0
04EE0FF0-511D-48F5-AA58-7600B3A69695 |18 |4 |201309 |5 |0
AB058AA5-6228-4E7C-9469-55827A5A34C3 |25 |69 |201108 |266 |0
大约有一百万行。列名 *ID 引用其他表,因此它们可以用作维度。
我有一个 OLAP 多维数据集,其中吞吐量列作为度量,其余列作为维度。
我想计算吞吐量度量的四分位 1 和 3。
我遵循了这个指南:https://electrovoid.wordpress.com/2011/06/24/ssas-quartile/ 连同这个 post:Calculating Quartiles in Analysis Services
来自那些我尝试使用此 MDX 查询的人:
WITH
SET selection as ([Dates].[Year].&[2014],[Dates].[Month].&[1])
SET [NonEmptyIds] AS
NonEmpty(
[ThroughputID].[ID].[id]
*[ThroughputID].[ID].[Id].ALLMEMBERS
,
{[Measures].[Throughput]} * [selection]
)
SET [ThroughputData] AS
ORDER
(
[NonEmptyIds],
[Measures].[Throughput],
BASC
)
MEMBER [Measures].[RowCount] AS COUNT (ThroughputData)
MEMBER [Measures].[i25] AS ( .25 * ( [RowCount] - 1 ) ) + 1
MEMBER [Measures].[i25Lo] AS FIX([i25]) - 1
MEMBER [Measures].[i25Rem] AS ([i25] - FIX([i25]))
MEMBER [Measures].[n25Lo] AS (ThroughputData.Item([i25Lo]), [Throughput])
MEMBER [Measures].[n25Hi] AS (ThroughputData.Item([i25Lo] + 1), [Throughput])
MEMBER [Measures].[Quartile1] AS [n25Lo] + ( [i25Rem] * ( [n25Hi] - [Throughput] ))
SELECT
selection ON 0,
[Measures].[Quartile1]
ON 1
FROM (SELECT [Dates].[Y-H-Q-M].MEMBERS ON 0 FROM [Throughput])
但我得到:'Query (6, 7) The ID hierarchy is used more than once in the Crossjoin function.'
我对 OLAP 和 MDX 很陌生。有什么问题吗?我应该如何计算正确的四分位数?
我在某处读到我需要 ID 维度才能在计算四分位数时获得包含所有值而不是聚合值的集合...
罪魁祸首是以下代码:
SET [NonEmptyIds] AS
NonEmpty(
[ThroughputID].[ID].[id]
*[ThroughputID].[ID].[Id].ALLMEMBERS
,
{[Measures].[Throughput]} * [selection]
)
您不能在交叉联接中多次使用同一层次结构。在这里您使用了 [ThroughputID].[ID]
两次。请尝试以下操作:
SET [NonEmptyIds] AS
NonEmpty(
[ThroughputID].[ID].[Id].ALLMEMBERS
,
{[Measures].[Throughput]} * [selection]
)