在MDX中实现IN / LIKE

时间:2019-05-30 16:25:40

标签: ssas mdx

我有一个名为[Band]的维度,它可以具有几个不同的值:

[Band].&[A]&[Under $400]
[Band].&[B]&[$400 - $1,000]
[Band].&[C]&[$1,000 - $2,500]
[Band].&[D]&[$2,500 - $3,500]
...

我正在尝试编写一个查询,在其中可以按这些值的子列表进行剪切。

这是因为.isin函数在MDX中不存在而无法使用的查询,但是您会看到我要执行的操作:

SELECT 
  NON EMPTY {[Measure A], [Measure B]} ON COLUMNS, 
  NON EMPTY {([Band].isin(['Under $400', '$400 - $1,000']).ALLMEMBERS)} --fail on .isin(
  DIMENSION PROPERTIES MEMBER_CAPTION ON ROWS
FROM (
  SELECT 
    ({[Foo].&[Bar]}) ON COLUMNS 
  FROM
    [CUBE]
)

现在,这是一个有效的查询,但它只给我一个[Band]值:

SELECT 
  NON EMPTY {[Measure A], [Measure B]} ON COLUMNS, 
  NON EMPTY {([Band].&[A]&[Under $400])}
  DIMENSION PROPERTIES MEMBER_CAPTION ON ROWS
FROM (
  SELECT 
    ({[Foo].&[Bar]}) ON COLUMNS 
  FROM
    [CUBE]
)

这将返回以下有效结果:

              Measure A    Measure B
Under $400    1795.67%     58.48%

但是我想在返回多个[Band]维值的聚合值的情况下查看结果。该如何在MDX中完成?

您可能会说我以前从未使用过MDX,但是在搜索此问题时,我看到类似taking the intersect或使用ChildrenSet之类的内容。但这似乎不是很直观。

你能指出我正确的方向吗?

2 个答案:

答案 0 :(得分:1)

So following is a list of how IsIn funcationality can be implemented in MDX

1)you want to filter using in clause and show the members too. In this example I want to see the internet sales for bikes and clothing category from adventurewroks sample db

select 
[Measures].[Internet Sales Amount]
on columns,
{[Product].[Category].&[1]
,[Product].[Category].&[3]}
on rows 
from 
[Adventure Works]

Result

enter image description here

2)I want to filter by the IN clause but dont want to show the members In this example I want to see yearly the internet sales for bikes and clothing category from adventurewroks sample db. The result is to be broken by years.

select 
[Measures].[Internet Sales Amount]
on columns,
non empty 
[Date].[Calendar Year].[Calendar Year]
on rows 
from 
[Adventure Works]
where 
{[Product].[Category].&[1]
,[Product].[Category].&[2]}

Result

enter image description here

You achive the same by using subquery

select 
[Measures].[Internet Sales Amount]
on columns,
non empty 
[Date].[Calendar Year].[Calendar Year]
on rows 
from 
(select {[Product].[Category].&[1],[Product].[Category].&[2]} on 0 from [Adventure Works])

Result

enter image description here

3)When you want to implement the IN clause based on name In this example I want to see the internet sales for bikes and clothing category from adventurewroks sample db, but in this case I am using the caption

select 
[Measures].[Internet Sales Amount]
on columns,
filter(
[Product].[Category].[Category],
[Product].[Category].currentmember.name='Bikes' or [Product].[Category].currentmember.name='Clothing'
)
on rows 
from 
[Adventure Works]

Result :

enter image description here

4) When you implement IN clause based on name and your condition is looking for a particular text (Like Clause ) In this example I want to see the internet sales for bikes and clothing category from adventurewroks sample db, but in this case I am searching the the caption name for a piece of string.

select 
[Measures].[Internet Sales Amount]
on columns,
FILTER([Product].[Category].[Category],
Instr([Product].[Category].currentmember.name, 'Bik') > 0
or 
Instr([Product].[Category].currentmember.name, 'oth') > 0
)
on rows 
from 
[Adventure Works]

Result

enter image description here

答案 1 :(得分:0)

弄明白了我的想法

SELECT 
  NON EMPTY {[Measure A], [Measure B]} ON COLUMNS, 
  NON EMPTY {[Band].[Under $400], [Band].[$1,000 - $2,500]}
  DIMENSION PROPERTIES MEMBER_CAPTION ON ROWS
FROM (
  SELECT 
    ({[Foo].&[Bar]}) ON COLUMNS 
  FROM
    [CUBE]
)