MDX在两个角色扮演维度中添加了两个立方体度量

时间:2013-01-11 15:20:56

标签: mdx olap aggregation olap-cube cross-join

我有两个想要加入的查询,这会给我计算行的总数。我遇到的问题是虽然措施来自1个事实表,但是Squad名称有两个角色扮演维度。我对MDX非常陌生。

结果将类似于

 | Competition    | Squad   | Goals A | Goals B | Total (Goals A + Goals B)|
 |----------------|---------|---------|---------|--------------------------|
 | Premier League | Arsenal | 25      | 15      | 40                       |

提前致谢。

查询1:

SELECT 
([Measures].[Goals A]) ON COLUMNS,
NON EMPTY ([Dim Competition].[Hierarchy].[Competition ID],[Squad A].[Squad Name].ALLMEMBERS) ON ROWS
FROM 
[FDC Star]
WHERE [Dim Competition].[Competition ID].&[1];

Query1结果:

Competition     Squad                 Goals A
Premier League  Arsenal                 25
Premier League  Aston Villa              8
Premier League  Chelsea                 22
Premier League  Everton                 17
Premier League  Fulham                  17
Premier League  Liverpool               17
Premier League  Manchester City         25
Premier League  Manchester United       28
Premier League  Newcastle United        13
Premier League  Norwich City            13
Premier League  Queens Park Rangers      8
Premier League  Reading                 15
Premier League  Southampton             15
Premier League  Stoke City              14
Premier League  Sunderland              11
Premier League  Swansea City            19
Premier League  Tottenham Hotspur       17
Premier League  West Bromwich Albion    17
Premier League  West Ham United         19

QUERY2:

SELECT 
([Measures].[Goals B]) ON COLUMNS,
NON EMPTY ([Dim Competition].[Hierarchy].[Competition ID],[Squad B].[Squad Name].ALLMEMBERS) ON ROWS
FROM 
[FDC Star]
WHERE [Dim Competition].[Competition ID].&[1];

Query2结果:

Competition     Squad                 Goals B
Premier League  Arsenal                 15
Premier League  Aston Villa              9
Premier League  Chelsea                 17
Premier League  Everton                 18
Premier League  Fulham                  15
Premier League  Liverpool               17
Premier League  Manchester City         16
Premier League  Manchester United       26
Premier League  Newcastle United        14
Premier League  Norwich City            11
Premier League  Queens Park Rangers      9
Premier League  Reading                  8
Premier League  Southampton             12
Premier League  Stoke City               7
Premier League  Sunderland              10
Premier League  Swansea City            12
Premier League  Tottenham Hotspur       22
Premier League  West Bromwich Albion    12
Premier League  West Ham United         5

2 个答案:

答案 0 :(得分:0)

您可以尝试这样的事情:

WITH MEMBER [Measures].[Goals B Linked]
AS (LinkMember([Squad A].[Squad Name].CurrentMember, [Squad B].[Squad Name]), [Measures].[Goals B]),
MEMBER [Measures].[Total]
AS [Measures].[Goals A] + [Measures].[Goals B Linked]

SELECT 
{[Measures].[Goals A], [Measures].[Goals B Linked], [Measures].[Total]}  ON COLUMNS,
NON EMPTY ([Dim Competition].[Hierarchy].[Competition ID],[Squad A].[Squad Name].ALLMEMBERS) ON ROWS
FROM 
[FDC Star]
WHERE [Dim Competition].[Competition ID].&[1];

答案 1 :(得分:0)

在花了很多时间试图找到解决方案后,我终于解决了我的问题。

由于

    WITH  
    MEMBER [Measures].[GFA] AS 
    (
    ([Measures].[Goals A]),
    linkmember([Dim Squad].[Squad Name],[Squad A].[Squad Name]),
    root([Squad Name])
    )
    MEMBER [Measures].[GFB] AS 
    (
    ([Measures].[Goals B]),
    linkmember([Dim Squad].[Squad Name],[Squad B].[Squad Name]),
    root([Squad Name])
    )
    MEMBER [MEASURES].[GF] AS
    (
        [Measures].[GFA] + [Measures].[GFB]
    )
    select 
    {[Measures].[GFA],[Measures].[GFB],[MEASURES].[GF]} on 0,
    non empty [Dim Squad].[Squad Name].allmembers on 1
    from [FDC Star]
    where [Dim Competition].[Competition ID].&[1]