如何在 mdx ssas 查询中按首字母分组

how to grouping by first letter in mdx ssas query

我的 MDX 脚本:

 SELECT NON EMPTY { [Measures].[Fact Emp Violation Count] } ON COLUMNS, NON EMPTY { ([Dim Date].[Calendar].[Year].ALLMEMBERS * [Dim Warning Level].[Violance Hierarchies].[Violance Type].ALLMEMBERS ) }  ON ROWS FROM ( SELECT ( { [Dim Date].[Calendar].[Year].&[2015] } ) ON COLUMNS FROM [Violation]) 

我的表:

我想根据暴力类型首字母分组

我想要的输出是:

Year     | Violence Type | Fact Emp Violation Count

CY 2015  |       1       | 19 + 18 + 2 + 23 + (violence type begins with '1')

CY 2015  |       2       | 11 + 4 + 1 + (violence type begins with '2')

谢谢。

首先,您需要对立方体设计进行小的更改,以使解决方案达到最佳。在 DSV 中,添加一个命名列并将其命名为 [New Violance Type]。该字段的逻辑很简单 -

=left([Violance Type], 1)

我预先计​​算它并将其存储在多维数据集中,这对您的 MDX 查询响应时间有奇效。虽然它也可以作为 MDX 的一部分进行计算,但它会降低性能。

将此字段添加到与新属性层次结构相同的维度 - [dim warning level].[New Violance Type]

然后你可以使用下面的 MDX -

select non empty { [measures].[fact emp violation count] } on columns, 
non empty { ([dim date].[calendar].[year].allmembers * [dim warning level].[New Violance Type].allmembers ) }  on rows 
from ( select ( { [dim date].[calendar].[year].&[2015] } ) on columns from [violation])