Udostępnij przez


Za pomocą funkcji zestawu

Funkcja zestawu pobiera zestaw wymiar, hierarchii, poziom lub przez przechodzenie lokalizacje względne i bezwzględne członków tych obiektów w ramach tworzenia zestawów w różny sposób.

Zestaw funkcji, takich jak element członkowski funkcje i funkcje spójna kolekcja są istotne do negocjowania wielowymiarowych struktur w usługach Analysis Services.Funkcje zestaw są również niezbędne do uzyskania wyniki z kwerendy Multidimensional Expressions (MDX) ponieważ wyrażenia zestaw definiuje osie kwerendy MDX.

Jednym z najbardziej typowych funkcji zestawu jest Członkowie (zbiór) (MDX) Funkcja, która pobiera zestaw zawierający wszystkie elementy członkowskie wymiar, hierarchii lub poziom.Oto przykład jego użycia w kwerendzie:

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]

Innego powszechnie wykorzystywana jest funkcja Połączenie krzyżowe (MDX) funkcji.Zwraca zestaw krotek, reprezentujących kartezjańskim zestawy przekazanemu jako parametry.W praktyce ta funkcja umożliwia tworzenie "zagnieżdżonych" lub "crosstabbed" osie w kwerendach:

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]

Elementy podrzędne (MDX) Przypomina funkcja Children działać, ale jest bardziej wydajne.Zwraca elementy podrzędne któregokolwiek element członkowski na jeden lub więcej poziomów w hierarchii:

WYBIERZ

[Środki].[Internet Sales Amount]

W kolumnach

//Returns zestaw zawierający wszystkie daty poniżej roku kalendarzowego

//2004 w hierarchii wymiar data kalendarza

ELEMENTY PODRZĘDNE)

[Data].[Kalendarz].[Rok kalendarzowy].&[2004]

, [Data].[Kalendarz].[Data])

W wierszach

Z [Adventure Works]

Zamówienia (MDX) Funkcja umożliwia zawartość zestaw w kolejności rosnącej lub malejącej zgodnie z określonego zamówienia wyrażenie liczbowe.Następująca kwerenda zwraca tych samych członków w wierszach jako poprzedniej kwerendy, ale teraz będą zamówień przez Internet Sales Amount miara:

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]

Ta kwerenda również ilustruje, jak zestaw zwrócony z jednego zestawu funkcja, elementy podrzędne, mogą być przekazywane jako parametr inny zestaw funkcja, zamówienia.

Zestaw zgodnie z niektórych kryteriów filtrowania jest bardzo przydatne podczas pisania kwerend i w tym celu można użyć Filtr (MDX) funkcja, jak pokazano w następującym przykładzie:

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]

Istnieją inne, więcej zaawansowanych funkcji, które pozwalają filtrować zestaw w inny sposób.Na przykład następujące kwerendy pokazuje TopCount (MDX) funkcja zwraca pierwsze n elementy w zestaw:

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]

Wreszcie jest możliwe do wykonania wielu operacji logicznej zestaw przy użyciu funkcji, takich jak Przetnij (MDX), Unia (MDX) i Z wyjątkiem (MDX) funkcji.Następująca kwerenda zawiera przykłady ostatnie dwie funkcje:

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]