我正在尝试使用MDX将两行中的详细信息显示为一行。如果我执行下面的MDX,它将返回2行,一行包含998键,另一行包含999键
SELECT NON EMPTY {
[Measures].[FactTableCount] } ON COLUMNS,
NON EMPTY { ([DimXXXX].[XXXXKey].[XXXXKey].ALLMEMBERS
* ([DimAAAA].[AAAAKey].[AAAAKey],{[DimBBBB].[Key].&[998],[DimBBBB].[Key].&[999]},[DimCCCC].[CCCCKey].[CCCCKey])
) } ON ROWS
FROM ( SELECT ( { [DimXXXX].[XXXXKey].&[MyValue] } ) ON COLUMNS
FROM [FactTable])
它返回这样的东西
(columns [DimXXXX].[XXXXKey], [DimAAAA].[AAAAKey], [DimBBBB].[Key], [DimCCCC].[CCCCKey], [Measures].[FactTableCount])
MyValue, MyAAAAKey1, 998, MyCCCCKey1, 1
MyValue, MyAAAAKey2, 999, MyCCCCKey2, 1
但是我希望像这样返回一行
`(columns [DimXXXX].[Key], [DimAAAA].[AAAAKey], [DimAAAA].[AAAAKey], [DimBBBB].[Key], [DimBBBB].[Key], [DimCCCC].[CCCCKey], [DimCCCC].[CCCCKey], [Measures].[FactTableCount])
MyValue, MyAAAAKey1, MyAAAAKey2, 998, 999, MyCCCCKey1, MyCCCCKey2, 1
除了其他的东西(比如使用SET,把ROWS / COLUMNS之后的998/999逻辑等),我试过了
SELECT NON EMPTY {
[Measures].[FactTableCount] } ON COLUMNS,
NON EMPTY { ([DimXXXX].[XXXXKey].[XXXXKey].ALLMEMBERS
* ([DimAAAA].[AAAAKey].[Key],[DimBBBB].[Key].&[998],[DimCCCC].[CCCCKey].[CCCCKey])
* ([DimAAAA].[AAAAKey].[Key],[DimBBBB].[Key].&[999],[DimCCCC].[CCCCKey].[CCCCKey])
) } ON ROWS
FROM ( SELECT ( { [DimXXXX].[XXXXKey].&[MyValue] } ) ON COLUMNS
FROM [FactTable])
...但是因为重复了AAAAKey层次结构,我收到错误消息“在Crossjoin函数中多次使用AAAAKey层次结构”
有办法做到这一点吗?
根据你在下面的评论,我有一个样本。让我知道它是否有效。
我想我可以看到你在说什么但是测量是一回事,但尺寸值是另一个 - 比如Record1:MyValue,MyAAAAKey1,998,MyCCCCKey1,2和Record2:MyValue,MyAAAAKey2,999,MyCCCCKey2,5-I想输出MyValue,MyAAAAKey1,MyAAAAKey2,998,999,MyCCCCKey1,MyCCCCKey2,2,5
所以在下面的查询中,我试图模拟你的问题。
select
{[Measures].[Internet Sales Amount]}
on columns,
non empty
([Customer].[City].[City],{[Product].[Category].&[1],[Product].[Category].&[3]},[Product].[Subcategory].[Subcategory])
on rows
from [Adventure Works]
现在的方法是将更改的值带到列,“{[Product]。[Category]。&1,[Product]。[Category]。&2}”在我的情况下和“{[DimBBBB]。[Key]。& [998],[DimBBBB]。[Key]。&[999]}“在你的情况下
select
{
({[Product].[Category].&[1],[Product].[Category].&[3]},[Measures].[Internet Sales Amount]),
([Product].[Category].defaultmember,[Measures].[Internet Order Quantity])
}
on columns,
non empty
([Customer].[City].[City],[Product].[Subcategory].[Subcategory])
on rows
from [Adventure Works]
请注意如何仅对相关列重复这些值。这确实添加了一个额外的列,但您的行现在是原始计数的一半。
编辑:根据评论处理要求
第一排的网格将是Ballard,Bikes,Mountain Bikes,Road Bikes。第二名:巴拉德,服装,帽子,手套。第3名:巴斯托,自行车,公路自行车,null。我想合并/列出实际的维度值
所以要实现上述目标,我们有两种选择。但无论哪种情况,都需要在UI上进行一些操作。 1)第一选择
with member
measures.t
as (nonempty(existing([Customer].[City].currentmember,[Product].[Category].currentmember,[Product].[Subcategory].[Subcategory].members),[Measures].[Internet Sales Amount])).item(0).item(2).name
member measures.t1
as (nonempty(existing([Customer].[City].currentmember,[Product].[Category].currentmember,[Product].[Subcategory].[Subcategory].members),[Measures].[Internet Sales Amount])).item(1).item(2).name
select
{measures.t,measures.t1}
on columns,
nonempty(([Customer].[City].[City],{[Product].[Category].&[1],[Product].[Category].&[3]}),[Measures].[Internet Sales Amount])
on rows
from [Adventure Works]
2)第二种选择,
with member
measures.t1
as
[Customer].[City].currentmember.name
member measures.t2
as
[Product].[Category].currentmember.name
member measures.t3
as (nonempty(existing([Customer].[City].currentmember,[Product].[Category].currentmember,[Product].[Subcategory].[Subcategory].members),[Measures].[Internet Sales Amount])).item(0).item(2).name
member measures.t4
as (nonempty(existing([Customer].[City].currentmember,[Product].[Category].currentmember,[Product].[Subcategory].[Subcategory].members),[Measures].[Internet Sales Amount])).item(1).item(2).name
select
{measures.t1,measures.t2,measures.t3,measures.t4}
on columns,
nonempty(([Customer].[City].[City],{[Product].[Category].&[1],[Product].[Category].&[3]}),[Measures].[Internet Sales Amount])
on rows
from [Adventure Works]