我们有一个user hierarchy
有3个级别(Level1是较高级别 - Level3是较低级别)
使用FILTER
函数我声明一个字符串,该字符串可以在任何(或几个)级别的任何成员的member_name
内。这会返回一个集合。
然后,我希望层次结构中的所有成员都与集合中的每个项目相关;上下两层。
我也尝试过(不成功)在结果中包含一个总是为Level2的列作为引用,也是一个排序列。
WITH
MEMBER [Measures].[LevelName] AS
[DimensionX].[HierX].Level.Name
MEMBER [Measures].[LevelNumber] AS
[DimensionX].[HierX].Level.Ordinal
MEMBER [Measures].[MemName] AS //<<<<<not working as I want level 2 in the result set
[DimensionX].[HierX].currentmember.membervalue
SET [Set_Target] AS
{
FILTER(
[DimensionX].[HierX].AllMembers,
(
InStr(
1,
[DimensionX].[HierX].currentmember.name,
"jesus") <> 0
)
)
}
SELECT
// ORDER(
// Exists(
// [AttributeHierX].members,
// [Set_Target]
// ),
// [AttributeHierX].[AttributeHierX].MEMBERVALUE
// )
//*
ORDER(
DESCENDANTS(
[Set_Target],
[DimensionX].[HierX].[Level1],
SELF_BEFORE_AFTER
),
[Measures].[LevelNumber],
BASC
) as X
ON 1,
{
[Measures].[MemName],
[Measures].[LevelName],
[Measures].[LevelNumber]
} ON 0
FROM [CubeX]
答案 0 :(得分:1)
我想在AdventureWorks上有一个类似的查询可以提供你想要的东西:
WITH
MEMBER [Measures].[LevelName] AS
[Employee].[Employee Department].CurrentMember.Level.Name
MEMBER [Measures].[LevelNumber] AS
[Employee].[Employee Department].CurrentMember.Level.Ordinal
MEMBER [Measures].[MemName] AS
[Employee].[Employee Department].CurrentMember.Name
SET [Set_TargetEmp] AS
{
FILTER(
[Employee Department].AllMembers,
(
InStr(
1,
[Employee].[Employee Department].currentmember.name,
"WC4") <> 0
)
)
}
SELECT
{
[Measures].[MemName],
[Measures].[LevelName],
[Measures].[LevelNumber]
} ON 0,
Hierarchize(
Generate([Set_TargetEmp] as e,
Ascendants(e.Current)
+
Descendants(e.Current, e.Current.Level, SELF_AND_AFTER)
)
)
ON 1
FROM [Adventure Works]
我使用Hierarchize
按层次结构对结果进行排序,因为这似乎是我检查结果的最简单方法。你可能想要改变它。因为 - 与Descendants
方法相反 - Ascendants
不允许将集合作为第一个参数,我使用Generate
来迭代集合。它的默认行为(没有All
的第三个参数),它消除了重复,我认为这是你需要的行为。