具有相同维度的 MDX 连接
MDX join with the same dimension
我正在编写一些 MDX 以根据两个不同的时间段将一个维度与其自身连接起来以获得一个公共列表,然后针对这两个时间段对这个列表进行计数。
总之,我需要
- 获取 Period1 的 Student.UniqueId 列表,其中设置的标志 (IsValid) 未在 Period2 数据中设置
- 获取第 2 期学生的完整列表
- 加入两个列表并产生两条具有相同计数的记录(每个周期一个)(这些计数将用于每个周期内的计算成员计算)
我试过通过带有过滤器的子选择和存在子句来做到这一点
SELECT
{
[Measures].[FactStudentCount]
} on COLUMNS,
{ NONEMPTY
(
[TestEvent].[TestEvents].[Name].ALLMEMBERS
* [TestEvent].[PeriodName].[PeriodName].ALLMEMBERS
)
} ON ROWS
FROM ( SELECT ( {
exists
(
filter([Student].[UniqueId].[UniqueId].MEMBERS
,([TestEvent].[Key].&[Period1], [IsValid].[Code].&[Yes]))
,
filter([Student].[UniqueId].[UniqueId].MEMBERS
,[TestEvent].[Key].&[Period2])
)
}) ON COLUMNS
FROM [MyCube])
...但是这并没有给出正确的结果
(获取上下文)我也在 where 子句中尝试过类似的 exists/filter
SELECT
{
[Measures].[FactStudentCount]
} on COLUMNS,
{ NONEMPTY
(
[TestEvent].[TestEvents].[Name].ALLMEMBERS
* [TestEvent].[PeriodName].[PeriodName].ALLMEMBERS
)
} ON ROWS
FROM [MyCube]
where (
exists
(
filter([Student].[UniqueId].[UniqueId].MEMBERS
,([TestEvent].[Key].&[Period1], [IsValid].[Code].&[Yes]))
,
filter([Student].[UniqueId].[UniqueId].MEMBERS
,[TestEvent].[Key].&[Period2])
)
)
...然而,这并没有产生正确的结果
我尝试将过滤器语句(在存在的范围内)调整为
(filter(existing([Student].[UniqueId].[UniqueId].allmembers),[TestEvent].[Key].CurrentMember.MemberValue = 'Period1'), [IsValid].[Code].&[Yes])
,
(filter(existing([Student].[UniqueId].[UniqueId].allmembers),[TestEvent].[Key].CurrentMember.MemberValue = 'Period2'))
...然而,这只有 returns 一行(对于 Period1)- 这表示它是正确的总数
我也尝试过通过带有 NonEmpty 的 CrossJoin 但它失败了,因为字段来自相同的层次结构 - 消息 "The Key hierarchy is used more than once in the Crossjoin function"
有没有人知道如何解决上述情况?
这就是我所做的
NonEmpty(
NonEmpty(
{([Student].[UniqueId].[UniqueId].members)},{([TestEvent].[Key].&[Period1], [IsValid].[Code].&[Yes])}
)
,
{([Student].[UniqueId].[UniqueId].members,[TestEvent].[Key].&[Period2])}
)
这会获取所有 Period1 元素,IsValid='Yes' 然后 'left joins' 这与 Period2
中的记录
我正在编写一些 MDX 以根据两个不同的时间段将一个维度与其自身连接起来以获得一个公共列表,然后针对这两个时间段对这个列表进行计数。
总之,我需要
- 获取 Period1 的 Student.UniqueId 列表,其中设置的标志 (IsValid) 未在 Period2 数据中设置
- 获取第 2 期学生的完整列表
- 加入两个列表并产生两条具有相同计数的记录(每个周期一个)(这些计数将用于每个周期内的计算成员计算)
我试过通过带有过滤器的子选择和存在子句来做到这一点
SELECT
{
[Measures].[FactStudentCount]
} on COLUMNS,
{ NONEMPTY
(
[TestEvent].[TestEvents].[Name].ALLMEMBERS
* [TestEvent].[PeriodName].[PeriodName].ALLMEMBERS
)
} ON ROWS
FROM ( SELECT ( {
exists
(
filter([Student].[UniqueId].[UniqueId].MEMBERS
,([TestEvent].[Key].&[Period1], [IsValid].[Code].&[Yes]))
,
filter([Student].[UniqueId].[UniqueId].MEMBERS
,[TestEvent].[Key].&[Period2])
)
}) ON COLUMNS
FROM [MyCube])
...但是这并没有给出正确的结果
(获取上下文)我也在 where 子句中尝试过类似的 exists/filter
SELECT
{
[Measures].[FactStudentCount]
} on COLUMNS,
{ NONEMPTY
(
[TestEvent].[TestEvents].[Name].ALLMEMBERS
* [TestEvent].[PeriodName].[PeriodName].ALLMEMBERS
)
} ON ROWS
FROM [MyCube]
where (
exists
(
filter([Student].[UniqueId].[UniqueId].MEMBERS
,([TestEvent].[Key].&[Period1], [IsValid].[Code].&[Yes]))
,
filter([Student].[UniqueId].[UniqueId].MEMBERS
,[TestEvent].[Key].&[Period2])
)
)
...然而,这并没有产生正确的结果
我尝试将过滤器语句(在存在的范围内)调整为
(filter(existing([Student].[UniqueId].[UniqueId].allmembers),[TestEvent].[Key].CurrentMember.MemberValue = 'Period1'), [IsValid].[Code].&[Yes])
,
(filter(existing([Student].[UniqueId].[UniqueId].allmembers),[TestEvent].[Key].CurrentMember.MemberValue = 'Period2'))
...然而,这只有 returns 一行(对于 Period1)- 这表示它是正确的总数
我也尝试过通过带有 NonEmpty 的 CrossJoin 但它失败了,因为字段来自相同的层次结构 - 消息 "The Key hierarchy is used more than once in the Crossjoin function"
有没有人知道如何解决上述情况?
这就是我所做的
NonEmpty(
NonEmpty(
{([Student].[UniqueId].[UniqueId].members)},{([TestEvent].[Key].&[Period1], [IsValid].[Code].&[Yes])}
)
,
{([Student].[UniqueId].[UniqueId].members,[TestEvent].[Key].&[Period2])}
)
这会获取所有 Period1 元素,IsValid='Yes' 然后 'left joins' 这与 Period2
中的记录