[英]How to implement "greater than" based on dimension value in MDX
我想查詢每個GDP增長率大於3的國家的總銷售額。目前,我可以這樣顯示每個國家的銷售額信息:
SELECT
{[Measures].[Sales]} ON 0,
{[Dim Company Info].[LOC].ALLMEMBERS} ON 1
FROM [Database]
但是后來我仍然對如何查詢所有超過 3 的 GDP 增長率一無所知。我搜索了 SO 並找到了過濾器作為答案,但是,我不知道將它包含在上面的代碼中的什么位置。 我怎么go一下這個?
編輯:我嘗試了以下方法,但我認為這不是我應該做的:
WHERE ([Dim Company Info].[Gdp Growth].&[3] : [Dim Company Info].[Gdp Growth].&[3].LastChild)
和
SELECT
{[Measures].[SALES]} ON 0,
{FILTER([Dim Company Info].[LOC].MEMBERS, [Dim Company Info].[Gdp Growth] > 3)} ON 1
FROM [766 Database]
和
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)
當維度成員按數字排列時,您可以使用以下表達式
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)
但是,如果不是這種情況,則需要按照以下方法進行操作。
我正在報告最大數量的產品。
select {[Measures].[Internet Sales Amount]} on 0,
non empty
([Product].[Product].[Product],[Promotion].[Max Quantity].[Max Quantity]) on 1
from [Adventure Works]
現在讓我們操縱最大數量,使其表現得像一個度量。
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]
現在您可以使用過濾器了,但是我們也需要轉換(注意 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.