我正在尝试编写一个MDX查询,我认为它类似于SQL中的where exists
。我们有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
(在LocA
或LocD
中没有)。总共有4个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
和FileA
的所有FileC
都返回,因为他们在SubFile
中至少有1个LocC
,而FileB
没有返回,因为它在SubFiles
没有LocC
。
如何在MDX中实现这一目标?
您可以使用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]