MDX:由另一个维度汇总的成员的不同计数
MDX: Distinct Count of members summarized by another dimension
从我的多维数据集中,我试图获得所有非空 [ID].[FullID]
的不同计数,但总结为 [Underlying]
。
我知道,例如,在这个特定的 WHERE 切片中有两个 [Underlying].[Underlying1]
的 ID,我可以通过下面的 MDX 查询 运行 看到这一点,这显然为我提供了一行每个(但计数为零?):
结果:
Underlying | FullID | CountOf
------------------------------
Underlying1 | ID1 | 0
Underlying1 | ID2 | 0
...
代码:
WITH
MEMBER CountOf AS
DistinctCount([ID].[FullID].Children)
SELECT
NON EMPTY {[Underlying].Children * [ID].[FullID].Children
} ON ROWS,
NON EMPTY {CountOf
} ON COLUMNS
FROM [MyCube]
WHERE ([Time].&[2018-11-27T00:00:00],
[Factor].[FactorName].[FACTOR1],
[Factor].[FactorType].[FACTORTYPE1]
[Location].[Location1]
)
然而,当我删除 * [ID].[FullID].Children
我没有得到想要的东西:
我想要的:
Underlying | CountOf
---------------------
Underlying1 | 2
...
我得到的:
Underlying | CountOf
---------------------
Underlying1 | 24
...
这里显然还有其他事情让我计数为 24,但我无法弄清楚...
您得到 24,因为您计算的是 [ID].[FullID].Children 中的成员。我的理解是,您想计算 [ID].[FullID] 的数量,这些人对 [Underlying].Children 具有针对他们的事实价值。所以你的代码应该是这样的
WITH
MEMBER CountOf AS
Count(
nonempty(([Underlying].currentmember,[ID].[FullID].Children),
[Measures].[ConnectingMeasure])
)
SELECT NON EMPTY {[Underlying].Children } ON ROWS,
NON EMPTY {CountOf} ON COLUMNS
FROM [MyCube]
WHERE ([Time].&[2018-11-27T00:00:00],[Factor].[FactorName].[FACTOR1],
[Factor].[FactorType].[FACTORTYPE1],[Location].[Location1]
)
以下是您想在 Adventureworks 中执行的操作示例。我正在尝试根据互联网销售数据计算产品的所有促销活动。
WITH
MEMBER CountOf AS
count(nonempty( ([Product].[Product].currentmember, [Promotion].[Promotion].children) ,[Measures].[Internet Sales Amount]))
SELECT
NON EMPTY {CountOf} ON COLUMNS,
NON EMPTY {
([Product].[Product].Children )
} ON ROWS
FROM [Adventure Works]
//基本查询以了解计数
WITH
MEMBER CountOf AS
Count(nonempty( ([Product].[Product].currentmember, [Promotion].[Promotion].children) ,[Measures].[Internet Sales Amount]))
SELECT
NON EMPTY [Measures].[Internet Sales Amount] ON COLUMNS,
NON EMPTY {
([Product].[Product].Children,[Promotion].[Promotion].children )
} ON ROWS
FROM [Adventure Works]
从我的多维数据集中,我试图获得所有非空 [ID].[FullID]
的不同计数,但总结为 [Underlying]
。
我知道,例如,在这个特定的 WHERE 切片中有两个 [Underlying].[Underlying1]
的 ID,我可以通过下面的 MDX 查询 运行 看到这一点,这显然为我提供了一行每个(但计数为零?):
结果:
Underlying | FullID | CountOf
------------------------------
Underlying1 | ID1 | 0
Underlying1 | ID2 | 0
...
代码:
WITH
MEMBER CountOf AS
DistinctCount([ID].[FullID].Children)
SELECT
NON EMPTY {[Underlying].Children * [ID].[FullID].Children
} ON ROWS,
NON EMPTY {CountOf
} ON COLUMNS
FROM [MyCube]
WHERE ([Time].&[2018-11-27T00:00:00],
[Factor].[FactorName].[FACTOR1],
[Factor].[FactorType].[FACTORTYPE1]
[Location].[Location1]
)
然而,当我删除 * [ID].[FullID].Children
我没有得到想要的东西:
我想要的:
Underlying | CountOf
---------------------
Underlying1 | 2
...
我得到的:
Underlying | CountOf
---------------------
Underlying1 | 24
...
这里显然还有其他事情让我计数为 24,但我无法弄清楚...
您得到 24,因为您计算的是 [ID].[FullID].Children 中的成员。我的理解是,您想计算 [ID].[FullID] 的数量,这些人对 [Underlying].Children 具有针对他们的事实价值。所以你的代码应该是这样的
WITH
MEMBER CountOf AS
Count(
nonempty(([Underlying].currentmember,[ID].[FullID].Children),
[Measures].[ConnectingMeasure])
)
SELECT NON EMPTY {[Underlying].Children } ON ROWS,
NON EMPTY {CountOf} ON COLUMNS
FROM [MyCube]
WHERE ([Time].&[2018-11-27T00:00:00],[Factor].[FactorName].[FACTOR1],
[Factor].[FactorType].[FACTORTYPE1],[Location].[Location1]
)
以下是您想在 Adventureworks 中执行的操作示例。我正在尝试根据互联网销售数据计算产品的所有促销活动。
WITH
MEMBER CountOf AS
count(nonempty( ([Product].[Product].currentmember, [Promotion].[Promotion].children) ,[Measures].[Internet Sales Amount]))
SELECT
NON EMPTY {CountOf} ON COLUMNS,
NON EMPTY {
([Product].[Product].Children )
} ON ROWS
FROM [Adventure Works]
//基本查询以了解计数
WITH
MEMBER CountOf AS
Count(nonempty( ([Product].[Product].currentmember, [Promotion].[Promotion].children) ,[Measures].[Internet Sales Amount]))
SELECT
NON EMPTY [Measures].[Internet Sales Amount] ON COLUMNS,
NON EMPTY {
([Product].[Product].Children,[Promotion].[Promotion].children )
} ON ROWS
FROM [Adventure Works]