Monday, November 2, 2015

MDX LastSibling Function

In Multidimensional Expression, LastSibling function will return the Last Child member that belongs to the parent of a specified member. For example, If you know single customer name and you want to find the Sales of a Last customer then you can use this LastSibling function.


TIP: You can use MDX FirstSibling Function to find the First Sibling.
MDX LastSibling Function Syntax


The basic syntax of the MDX LastSibling is:


Member_Expression.LASTSIBLING

Member_Expression: Any Multidimensional Expression that returns valid Member.


In this article we will show you, How to write LastSibling function in MDX query with examples. For this, We are going to use the below show data


Following screenshot shows the Countries inside the Geography





Following screenshot shows the [State – Provinces] inside the France Country






MDX LastSibling Function Example

If we know the Loiret is one of the state in France and our intention is to find the Last state present in France then, we can use this LastSibling function. In this example we are going to find the Last Children present in the State Province list and calculate the Reseller Sales Amount of that.


CODE


SELECT
[Measures].[Reseller Sales Amount] ON COLUMNS,
[Geography].[Geography].[State-Province].[Loiret].LASTSIBLING ON ROWS
FROM [Adventure Works];


OUTPUT



MDX LastSibling Function Example


In this example we are going to find the Last Children present in the Countries list.


CODE


SELECT
[Measures].[Reseller Sales Amount] ON COLUMNS,
[Geography].[Geography].[Country].[France].LASTSIBLING ON ROWS
FROM [Adventure Works];


OUTPUT





Analysis:

In the above MDX Query, We used [Reseller Sales amount] on the columns

[Measures].[Reseller Sales Amount] ON COLUMNS


Below line of code will check for the France parent (Which is All member) and then finds the Last child member of the Country.


[Geography].[Geography].[Country].[France].LASTSIBLING


MDX LastSibling Function Alternative


In this example we are going to use the LastSibling function alternative to achieve the same result. Please refer MDX Parent Function to understand the Parent function and refer MDX LastChild function to understand the LastChild function.


CODE


SELECT
[Measures].[Reseller Sales Amount] ON COLUMNS,
[Geography].[Geography].[Country].[France].PARENT.LASTCHILD ON ROWS
FROM [Adventure Works];


OUTPUT