次の方法で共有


集合関数の使用

集合関数は、ディメンション、階層、レベルからセットを取得します。あるいは、それらのオブジェクト内でのメンバーの絶対位置および相対位置をトラバースすることにより、さまざまな方法でセットを構築します。

メンバー関数やタプル関数などのセット関数は、Analysis Services で見つかった多次元構造のネゴシエートに不可欠です。 セット式は MDX クエリの軸を定義するため、セット関数は多次元式 (MDX) クエリから結果を取得するためにも不可欠です。

最も一般的なセット関数 の 1 つは Members (Set) (MDX) 関数です。この関数は、ディメンション、階層、またはレベルからすべてのメンバーを含むセットを取得します。 クエリ内でのこの関数の使用例を次に示します。

SELECT

//Returns all of the members on the Measures dimension

[Measures].MEMBERS

ON Columns,

//Returns all of the members on the Calendar Year level of the Calendar Year Hierarchy

//on the Date dimension

[Date].[Calendar Year].[Calendar Year].MEMBERS

ON Rows

FROM [Adventure Works]

もう 1 つの一般的に使用される関数は、 クロス結合 (MDX) 関数です。 この関数は、パラメーターとして渡されるセットのデカルト積を表す組のセットを返します。 実際には、この関数を使用すると、クエリで "入れ子になった" 軸または "クロス集計" 軸を作成できます。

SELECT

//Returns all of the members on the Measures dimension

[Measures].MEMBERS

ON Columns,

//Returns a set containing every combination of all of the members

//on the Calendar Year level of the Calendar Year Hierarchy

//on the Date dimension and all of the members on the Category level

//of the Category hierarchy on the Product dimension

Crossjoin(

[Date].[Calendar Year].[Calendar Year].MEMBERS,

[Product].[Category].[Category].MEMBERS)

ON Rows

FROM [Adventure Works]

Descendants (MDX) 関数は Children 関数に似ていますが、より強力です。 階層内の 1 つ以上のレベルにあるメンバーの子孫が返されます。

選択

[メジャー]。[インターネット販売額]

ON Columns,

//Returns a set containing all of the Dates beneath Calendar Year

日付ディメンションのカレンダー階層の 2004

DESCENDANTS(

[日付]。[カレンダー]。[暦年].>[2004]

, [Date].[Calendar].[Date])

ON Rows

FROM [Adventure Works]

Order (MDX) 関数を使用すると、特定の数値式に従って、セットの内容を昇順または降順で並べ替えられます。 次のクエリでは、前のクエリと同じメンバーが行に対して返されますが、現在は Internet Sales Amount メジャーで並べ替えられます。

SELECT

[Measures].[Internet Sales Amount]

ON Columns,

//Returns a set containing all of the Dates beneath Calendar Year

//2004 in the Calendar hierarchy of the Date dimension

//ordered by Internet Sales Amount

ORDER(

DESCENDANTS(

[Date].[Calendar].[Calendar Year].&[2004]

, [Date].[Calendar].[Date])

, [Measures].[Internet Sales Amount], BDESC)

ON Rows

FROM [Adventure Works]

このクエリでは、あるセット関数 Descendants から返されたセットをパラメーターとして別の set 関数 Order に渡す方法も示します。

特定の条件に従ってセットをフィルター処理することは、クエリを記述する場合に非常に便利です。このため、次の例に示すように Filter (MDX) 関数を使用できます。

SELECT

[Measures].[Internet Sales Amount]

ON Columns,

//Returns a set containing all of the Dates beneath Calendar Year

//2004 in the Calendar hierarchy of the Date dimension

//where Internet Sales Amount is greater than $70000

FILTER(

DESCENDANTS(

[Date].[Calendar].[Calendar Year].&[2004]

, [Date].[Calendar].[Date])

, [Measures].[Internet Sales Amount]>70000)

ON Rows

FROM [Adventure Works]

また、他の方法でセットにフィルターを適用できるようにする、さらに高度な関数もあります。 たとえば、次のクエリは、TopCount (MDX) 関数がセット内の上位 n 個の項目を返す場合を示しています

SELECT

[Measures].[Internet Sales Amount]

ON Columns,

//Returns a set containing the top 10 Dates beneath Calendar Year

//2004 in the Calendar hierarchy of the Date dimension by Internet Sales Amount

TOPCOUNT(

DESCENDANTS(

[Date].[Calendar].[Calendar Year].&[2004]

, [Date].[Calendar].[Date])

,10, [Measures].[Internet Sales Amount])

ON Rows

FROM [Adventure Works]

最後に、Intersect (MDX)、Union (MDX)、Except (MDX)関数などの関数を使用して、いくつかの論理セット操作を実行できます。 次のクエリは、後者の 2 つの関数の例を示しています。

SELECT

//Returns a set containing the Measures Internet Sales Amount, Internet Tax Amount and

//Internet Total Product Cost

UNION(

{[Measures].[Internet Sales Amount], [Measures].[Internet Tax Amount]}

, {[Measures].[Internet Total Product Cost]}

)

ON Columns,

//Returns a set containing all of the Dates beneath Calendar Year

//2004 in the Calendar hierarchy of the Date dimension

//except the January 1st 2004

EXCEPT(

DESCENDANTS(

[Date].[Calendar].[Calendar Year].&[2004]

, [Date].[Calendar].[Date])

,{[Date].[Calendar].[Date].&[915]})

ON Rows

FROM [Adventure Works]

参照

関数 (MDX 構文)
メンバー関数の使用
組関数の使用