MDX

Intersect

Intersect returns only members that appear in both of two sets. One example might be to show products that performed well both last year and this year, or customers that are both high volume and high margin. The default is to drop duplicates although “, ALL” can be added if these are required.

Union

Union joins two sets together, returning the members of each set, optionally retaining or dropping duplicates (default is to drop).

This creates a single list of the top 5 and worst 5 products.
{UNION(
TOPCOUNT( {TM1FILTERBYLEVEL( {TM1SUBSETALL( [Product] )}, 0)}, 5, [Test].([Posting Measures].[Amount]) ),
BOTTOMCOUNT( {TM1FILTERBYLEVEL( {TM1SUBSETALL( [Product] )}, 0)}, 5, [Test].([Posting Measures].[Amount]) )
)}

Head, Tail and Subset

Where TopCount and BottomCount sort the values automatically and chop the list to leave only the most extreme values, Head combined with Filter works in a similar manner but Head then returns the FIRST members of the filtered set in their original dimension order.

These queries simply return the first and last members of the Product dimension as listed when you hit the ‘All’ button:
{Head ( TM1SubsetAll ( [Product] ) )}
{Tail ( TM1SubsetAll ( [Product] ) )}

Filtering by Attributes and logical operators

This returns members that match a certain attribute value using the Filter function.
{FILTER( {TM1SUBSETALL( [Product] )}, [Product].[Category] = "Customer Lending")}

This example looks at multiple attribute values to return a filtered list:
{
FILTER(
    {TM1SUBSETALL( [Product] )},
    (
    ([Product].[Category]="Customer Lending" OR [Product].[Type]="Debit")
    AND
    ([Product].[Internal Deal]<>"No")
    )
    )
}

Filtering by CurrentMember, NextMember, PrevMember, Ancestor and FirstSibling

This example returns the members that have an Amount value in the Test cube above 18. The [Product].CurrentMember part is optional here but it makes the next example clearer.
{FILTER( {TM1FILTERBYLEVEL( {TM1SUBSETALL( [Product] )}, 0)},
[Test].([Product].CurrentMember, [Posting Measures].[Amount]) > 18 )}

Lag, Lead, NextMember, PrevMember, FirstSibling, LastSibling, Siblings and LastPeriods

Lags and Leads are the equivalent of Dnext/Dprev.
{ [Date].[2006-10-03].Lead(1) }
will return 2006-10-04.

Lead(n) is the same as Lag(-n) so either function can be used in place of the other by using a negative value, but if only one direction will ever be needed in a given situation then you should use the correct one for understandability’s sake. Note that they only return a single member so to return the set of members between two members you can use the lastperiods function.

Parent, Children, FirstChild, LastChild, Ancestors, Descendants, DrillDownLevel and TM1DrilldownMember

Children returns the set of members one level below a named parent.
{Product.[Demand Loan].Children}

FirstChild returns the… first child one level below a named parent.
{[Product].[Customer Lending].FirstChild}
Returns “Call Participation Purchased”.

Filter, by values, strings and attributes

The FILTER function is used to filter the dimension based on some kind of data values rather than just the members and their hierarchy on their own. This data might be cube data (numeric or string) or attribute data. This requires a change of thinking from straightforward single dimensions (lists with a hierarchy and occasionally some attributes) to a multi-dimensional space, where every dimension in these cubes must be considered and dealt with.

TopCount and BottomCount

A classic Top 10 command:
{ TOPCOUNT( {TM1FILTERBYLEVEL( {TM1SUBSETALL( [Product] )}, 0)}, 10, [Test].([Posting Measures].[Amount]) )}
By omitting a sort order it sorts in the default order (which has the values descending in value and breaks any hierarchies present).

TM1Sort, TM1SortByIndex and Order

TM1Sort is the equivalent of pressing one of the two Sort Ascending or Sort Descending buttons in the subset editor – i.e. sort alphabetically.

TM1SortIndex is the equivalent of pressing one of the two Sort by index, ascending or Sort by index, descending buttons in the subset editor – i.e. sort by the dimension index (dimix).

Order is a standard MDX function that uses a data value from a cube to perform the sort. For example, sort the list of customers according to the sales, or a list of employees according to their length of service.