Return 同一父项中至少有一个子项的所有子项

Return all children where at least one exists in same parent

我正在尝试编写一个我认为类似于 SQL 中的 where exists 的 MDX 查询。我们有 FilesSubFiles 组成,每个 SubFile 都在 Location 中。 Locations 有一个维度,Files 有一个维度(包含 File -> SubFile 层次结构),以及所有 SubFiles.

的度量计数

所以下面的 MDX:

select
    [Location].[Location].members on 0,
    [File].[File].members on 1
from
    [MyCube]

return类似于:

             | LocA | LocB | LocC | LocD
----------------------------------------
FileA        | null |  2   |   2  | null
FileB        |  1   |  2   | null | null
FileC        | null | null |   1  |  2

这表明,例如,FileALocB 中有 2 个 SubFiles,在 LocC 中有 2 个 SubFiles(和 none 在 LocALocD 中)。它总共有 4 SubFiles 个。

我需要实现的是,对于给定的 Location return 所有 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

所以 all SubFiles for FileAFileC 被 returned 因为它们至少有 1 SubFileLocC 中,而 FileB 没有 return,因为它在 LocC.

中没有 SubFiles

如何在 MDX 中实现这一点?

您可以使用Exists function to get the Files, and then the 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]