MDX记录计数

问题描述 投票:0回答:5

任何人都可以告诉我如何获取MDX查询结果的记录数吗?我尝试了各种方法,但我还没有真正得到解决方案。我是MDX查询的初学者。

mdx
5个回答
0
投票

在多维数据集中创建一个计数或不同计数的度量。


0
投票

1)打开立方体

2)右键单击该度量所在的事实表

3)选择New Measure...

4)下拉列表并选择聚合

5)在源列部分中,选择要聚合的列(如果无法找到它,请单击底部的show all columns-这取决于您聚合的内容)


0
投票
WITH 
    MEMBER [Measures].[amount] as 
        COUNT(
            [your_dimension].[your_dimension_property].Members
        ) 
SELECT {[Measures].[amount]} ON COLUMNS 
FROM [your_awesome_cube] 

这样的代码将返回维度中的成员数量,COUNT方法具有此语法Count(Set_Expression [ , ( EXCLUDEEMPTY | INCLUDEEMPTY ) ] ),因此您可以执行很多操作,例如过滤搜索


0
投票

将成员Measures.Counts作为[your_dimension]。[your_dimension_property] .Children.COUNT

选择Measures.Counts on 0 FROM [your_awesome_cube]


0
投票

当您说记录计数时,您基本上是在说行轴的有效组合。

让我们举一个基本的例子,查询返回3637行,其中1行是列名行。

select [Measures].[Sales Amount] on columns, 
(
[Customer].[Country].[Country],
[Product].[Product].[Product]
) on rows
from [Adventure Works]

现在要在不运行查询的情况下获取行计数,让我们将组合放在count函数中,并将count函数放在运行时度量中

这返回3636行。使用成员[Measures]。[rowCount]作为计数(([Customer]。[Country]。[Country],[Product]。[Product]。[Product]))选择[Measures]。[rowCount]列中的[冒险作品]

注意我没有消除行上的空组合。我们接下来就这样做

该查询返回2101行,再次从列标题返回一行。选择[测量]。[销售金额]列,非空([客户]。[国家]。[国家],[产品]。[产品]。[产品])来自[Adventure Works]的行

现在让我们计算行数

这将返回2100行。成员[Measures]。[rowCount] as count(非空(([客户]。[国家]。[国家],[产品]。[产品]。[产品]),{[措施]。[销售额]} ))从[Adventure Works]的列中选择[Measures]。[rowCount]

到目前为止,我们只从一个度量组中进行测量,现在让我们尝试使用多个度量组。

select {[Measures].[Sales Amount],[Measures].[Internet Sales Amount]} on columns, 
non empty 
(
[Customer].[Country].[Country],
[Product].[Product].[Product]
) on rows
from [Adventure Works]
//Cell set consists of 2101 rows and 3 columns.

//Wrong way
with member [Measures].[rowCount]
as 
count(nonempty(( [Customer].[Country].[Country],[Product].[Product].[Product])
,{[Measures].[Internet Sales Amount]}
))
select [Measures].[rowCount] on columns from [Adventure Works]
//935

//Right way
with member [Measures].[rowCount]
as 
count(nonempty(( [Customer].[Country].[Country],[Product].[Product].[Product])
,{[Measures].[Sales Amount],[Measures].[Internet Sales Amount]}
))
select [Measures].[rowCount] 
on columns from [Adventure Works]
///2100

请注意,当我们仅使用一个度量时,结果可能不正确。如果我们使用的度量值为空值,则将删除该组合。在我们的行中,另一个度量将确保组合出现。

现在让我们为图片添加一个过滤器。

select {[Measures].[Sales Amount],[Measures].[Internet Sales Amount]} on columns, 
non empty
filter( 
(
[Customer].[Country].[Country],
[Product].[Product].[Product]
)
,[Measures].[Internet Sales Amount]>5000) on rows
from [Adventure Works]
//Cell set consists of 586 rows and 3 columns.

//Wrong way
with member [Measures].[rowCount]
as 
count(nonempty(( [Customer].[Country].[Country],[Product].[Product].[Product])
,{[Measures].[Sales Amount],[Measures].[Internet Sales Amount]}
))
select [Measures].[rowCount] 
on columns from [Adventure Works]
//2100

//Right way
with member [Measures].[rowCount]
as 
count(nonempty(
filter(([Customer].[Country].[Country],[Product].[Product].[Product]),[Measures].[Internet Sales Amount]>5000) 
,{[Measures].[Sales Amount],[Measures].[Internet Sales Amount]}
))
select [Measures].[rowCount] 
on columns from [Adventure Works]
///585

再一次,直到我给行计数测量我在行轴上的确切情况它失败了。

© www.soinside.com 2019 - 2024. All rights reserved.