MDX如何获得子组的总和?

时间:2017-08-23 12:24:06

标签: ssas mdx

我有以下MDX查询:

SELECT
NON EMPTY { [Measures].[Sales Amount] } ON COLUMNS,
NON EMPTY { ([Customer].[City].[City] * [Customer].[Gender].[Gender] ) } ON ROWS
FROM [Analysis Services Tutorial]

如您所知,此MDX查询获取以下表格结果:

|---------------------|-----------|---------------|
|        City         |   Gender  |  Sales Amount |
|---------------------|-----------|---------------|
|     Ballard         |     F     |    300        |
|---------------------|-----------|---------------|
|     Ballard         |     M     |    500        |
|---------------------|-----------|---------------|
|     Berkeley        |     F     |    200        |
|---------------------|-----------|---------------|
|     Berkeley        |     M     |    100        |
|---------------------|-----------|---------------|
                      .
                      .
                      .

但我需要表格中的小计:

|---------------------|-----------|---------------|
|        City         |   Gender  |  Sales Amount |
|---------------------|-----------|---------------|
|     Ballard         |     F     |    300        |
|---------------------|-----------|---------------|
|     Ballard         |     M     |    500        |
|---------------------|-----------|---------------|
|     Ballard         |    All    |    800        |
|---------------------|-----------|---------------|
|     Berkeley        |     F     |    200        |
|---------------------|-----------|---------------|
|     Berkeley        |     M     |    100        |
|---------------------|-----------|---------------|
|     Berkeley        |    All    |    300        |
|---------------------|-----------|---------------|
                      .
                      .
                      .

在MDX中是否有任何建议?任何帮助,将不胜感激。感谢

2 个答案:

答案 0 :(得分:1)

您可以尝试此查询

SELECT
NON EMPTY { [Measures].[Sales Amount] } ON COLUMNS,
NON EMPTY { ([Customer].[City].[City] * [Customer].[Gender].allmembers ) } ON ROWS
FROM [Analysis Services Tutorial]

您通常需要使用allmembers才能显示All成员。如果它没有返回All成员,那么你需要计算它

WITH Member [Customer].[Gender].[All Genders] AS [Customer].[Gender].&[M] + 
                                                 [Customer].[Gender].&[F] 
SELECT
NON EMPTY { [Measures].[Sales Amount] } ON COLUMNS,
NON EMPTY { ([Customer].[City].[City] * [Customer].[Gender].allmembers ) } ON ROWS
FROM [Analysis Services Tutorial]

答案 1 :(得分:0)

您可以添加ALL成员:

SELECT
NON EMPTY [Measures].[Sales Amount] ON COLUMNS,
NON EMPTY [Customer].[City].[City].Members * {[Customer].[Gender].[Gender].Members + [Customer].[Gender].[All]} ON ROWS
FROM [Analysis Services Tutorial]

或性别等级的所有成员:

SELECT
NON EMPTY { [Measures].[Sales Amount] } ON COLUMNS,
NON EMPTY [Customer].[City].[City].Members * [Customer].[Gender].Members ON ROWS
FROM [Analysis Services Tutorial]