MDX查询添加SUM列

时间:2014-09-20 02:13:32

标签: sql mdx olap-cube ssas-2008

我写了以下MDX

WITH MEMBER [Measures].[SumReturns] AS
  ([Dimension1].[GCode].defaultmember,[Measures].[GScore Sum])  

SELECT
   non empty  
   (  

      {[Dimension1].[Description].children},  
      {[Dimension1].[GCode].children},  
      {
         [Measures].[GScore Sum],  
         [Measures].[SumReturns]  
      }

   )  
   on columns,  
   non empty
   (
      [Dimension2].[DCode].[DCode] *  
      [Dimension2].[DName].[DName] *   
      [Dimension2.[Barcode].[Barcode] *  
      [Dimension2].[LN].[LName] *  
      [Dimension2].[FN].[FName]   

   )
   on rows
FROM [MCube]
WHERE 
(
   {[Dimension2].[HARC].[DCode].&[0000]}
)  

查询给出了以下结果:

Actual Results

但我所期望的是这些结果:

Expected Results

有关如何获得所需结果的任何建议?

2 个答案:

答案 0 :(得分:0)

为什么不总结SubCat1和SubCat2?为什么选择默认会员?这就是全部吗?

总结一下这就是你需要的代码:

with member [Dimension1].[GCode].[SumReturns] as
SUM([Dimension1].[Description].children , [Measures].[GScore Sum])

select  
non empty  
(  

[Dimension1].[Description].children * 
[Dimension1].[GCode].children

)  
on columns,  
non empty
(
[Dimension2].[DCode].[DCode] *  
[Dimension2].[DName].[DName] *   
[Dimension2.[Barcode].[Barcode] *  
[Dimension2].[LN].[LName] *  
[Dimension2].[FN].[FName]   

)
on rows
from 
[MCube]

where 
(



{[Dimension2].[HARC].[DCode].&[0000]}

)  

答案 1 :(得分:0)

以下是用于获取所需结果的查询。无需计算度量

 select  
    non empty  
    (      
    [Dimension1].[Description].children,  
    [Dimension1].[GCode].members,  
    [Measures].[GScore Sum]   
    )  
    on columns,  
    non empty
    (
    [Dimension2].[DCode].[DCode] *  
    [Dimension2].[DName].[DName] *   
    [Dimension2.[Barcode].[Barcode] *  
    [Dimension2].[LN].[LName] *  
    [Dimension2].[FN].[FName]   

    )
    on rows
    from 
    [MCube]
    where 
    (

    {[Dimension2].[HARC].[DCode].&[0000]}

    )