简体   繁体   English

如何在MDX中实现基于维度值的“大于”

[英]How to implement "greater than" based on dimension value in MDX

I would like to query the total sales of each country with the GDP growth rate of more than 3. So far, I can display the sales information of each country like such:我想查询每个GDP增长率大于3的国家的总销售额。目前,我可以这样显示每个国家的销售额信息:

SELECT 
{[Measures].[Sales]} ON 0,
{[Dim Company Info].[LOC].ALLMEMBERS} ON 1
FROM [Database]

But then I am still blank on how to query all GDP growth rate of more than 3. I have searched SO and found filter to be the answer, however, I do not know where to include it in my code above.但是后来我仍然对如何查询所有超过 3 的 GDP 增长率一无所知。我搜索了 SO 并找到了过滤器作为答案,但是,我不知道将它包含在上面的代码中的什么位置。 How do I go about this?我怎么go一下这个?

Edit: I have tried the followings, but I do not think that is what I am supposed to do:编辑:我尝试了以下方法,但我认为这不是我应该做的:

WHERE ([Dim Company Info].[Gdp Growth].&[3] : [Dim Company Info].[Gdp Growth].&[3].LastChild)

and

SELECT 
{[Measures].[SALES]} ON 0,
{FILTER([Dim Company Info].[LOC].MEMBERS, [Dim Company Info].[Gdp Growth] > 3)} ON 1
FROM [766 Database]

and

SELECT 
{[Measures].[SALES]} ON COLUMNS,
{[Dim Company Info].[LOC].MEMBERS} ON ROWS
FROM [766 Database]
WHERE FILTER([Dim Company Info].[Gdp Growth], [Dim Company Info].[Gdp Growth] > 2)

You can use your below expression when the dimension members are numericly arranged当维度成员按数字排列时,您可以使用以下表达式

WHERE ([Dim Company Info].[Gdp Growth].& 3 : [Dim Company Info].[Gdp Growth].& 3 .LastChild) with a slight correction WHERE ([Dim Company Info].[Gdp Growth].& 3 : [Dim Company Info].[Gdp Growth].& 3 .LastChild) 稍作修正

WHERE ([Dim Company Info].[Gdp Growth].&[3] : [Dim Company Info].[Gdp Growth].[Gdp Growth].LastChild)

However if that is not the case, then you need to follow the below method.但是,如果不是这种情况,则需要按照以下方法进行操作。

I am reporting the product with the max quantity.我正在报告最大数量的产品。

select {[Measures].[Internet Sales Amount]} on 0,
non empty
([Product].[Product].[Product],[Promotion].[Max Quantity].[Max Quantity]) on 1 
from [Adventure Works]

在此处输入图像描述

Now lets manipulate the max quantity to make it behave like a measure.现在让我们操纵最大数量,使其表现得像一个度量。

with 
member measures.test
as 
case when [Measures].[Internet Sales Amount]>0 then 
(nonempty(([Product].[Product].currentmember,[Promotion].[Max Quantity].[Max Quantity]),[Measures].[Internet Sales Amount])).item(0).item(1).name
else 
null end

select
{[Measures].[Internet Sales Amount],measures.test}
on 0,
non empty ([Product].[Product].[Product] )
on 1 
from [Adventure Works]

在此处输入图像描述

Now you can use the filter, but we need to cast(note the use of CInt) the data too现在您可以使用过滤器了,但是我们也需要转换(注意 CInt 的使用)数据

with 
member measures.test
as 
case when [Measures].[Internet Sales Amount]>0 then 
Cint((nonempty(([Product].[Product].currentmember,[Promotion].[Max Quantity].[Max Quantity]),[Measures].[Internet Sales Amount])).item(0).item(1).name)
else 
null end

select
{[Measures].[Internet Sales Amount],measures.test}
on 0,
non empty (
filter(
[Product].[Product].[Product]
,measures.test>0) 
)
on 1 
from [Adventure Works]

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM