The MDX LastSibling function will return the Last Child member that belongs to the parent of a specified member. For example, If you know a single customer name and you want to find the Sales of the Last customer, then you can use this MDX Last Sibling function.
The basic syntax of the MDX LastSibling in Multidimensional Expression is as shown below:
Member_Expression.LASTSIBLING
Member_Expression: Any Multidimensional Expression that returns a valid Member.
For this LastSibling function in query, We are going to use the below show data The following screenshot shows the Countries inside the Geography
The following screenshot shows the [State – Provinces] inside the France Country
MDX LastSibling Function Example
If we know the Loiret is one of the states in France and we intend 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.
TIP: You can use the MDX FirstSibling Function to find the First Sibling.
SELECT [Measures].[Reseller Sales Amount] ON COLUMNS, [Geography].[Geography].[State-Province].[Loiret].LASTSIBLING ON ROWS FROM [Adventure Works];
MDX LastSibling Function Example
In this example, we are going to find the Last Children present in the Countries list.
SELECT [Measures].[Reseller Sales Amount] ON COLUMNS, [Geography].[Geography].[Country].[France].LASTSIBLING ON ROWS FROM [Adventure Works];
In the above MDX Query, We used [Reseller Sales amount] on the columns
[Measures].[Reseller Sales Amount] ON COLUMNS
The below line of code will check for the France parent (Which is All members) and then find the Last child member of the Country.
[Geography].[Geography].[Country].[France].LASTSIBLING
LastSibling Function Alternative
In this example, we are going to use the LastSibling function alternative to achieve the same result. Please refer to the MDX Parent Function to understand the Parent function and refer to the MDX LastChild function to understand the LastChild function.
SELECT [Measures].[Reseller Sales Amount] ON COLUMNS, [Geography].[Geography].[Country].[France].PARENT.LASTCHILD ON ROWS FROM [Adventure Works];