我正在尝试编写一个我认为与SQL中的where exists
类似的MDX查询。我们有Files
,它们是由SubFiles
组成的,每个SubFile
都在Location
中。 Locations
有一个维度,Files
有一个维度(包含File -> SubFile
层次结构),所有SubFiles
都有一个度量值计数。
因此,以下MDX:
select
[Location].[Location].members on 0,
[File].[File].members on 1
from
[MyCube]
返回类似的内容
| LocA | LocB | LocC | LocD
----------------------------------------
FileA | null | 2 | 2 | null
FileB | 1 | 2 | null | null
FileC | null | null | 1 | 2
这表明,例如FileA
在SubFiles
中有2个LocB
,在SubFiles
中有2个LocC
(在{{1}中没有) }或LocA
)。它总共有4 LocD
。
我需要实现的是,对于给定的SubFiles
,请返回所有Location
,其中在同一SubFiles
下的至少一个 SubFile
是在给定的File
中。因此,对于上述示例,如果给定位置为Location
,则结果集应为:
LocC
因此,返回 | LocA | LocB | LocC | LocD
----------------------------------------
FileA |
SubFileA1 | null | null | 1 | null
SubFileA2 | null | 1 | null | null
SubFileA3 | null | 1 | null | null
SubFileA4 | null | null | 1 | null
FileC |
SubFileC1 | null | null | null | 1
SubFileC2 | null | null | 1 | null
SubFileC3 | null | null | null | 1
和SubFiles
的 all FileA
,因为它们在FileC
中至少有1个SubFile
,而由于LocC
中没有FileB
,因此未返回SubFiles
。
如何在MDX中实现这一目标?
答案 0 :(得分:1)
您可以使用Exists
function获取文件,然后使用Descendants
function添加子文件:
select
[Location].[Location].members
on 0,
Descendants(
Exists(
[File].[File -> SubFile].[File].members,
{[Location].[Location].[LocC]}
),
[File].[File -> SubFile].[SubFile],
SELF_AND_BEFORE
)
on 1
from
[MyCube]