MDX LastChild Function

The MDX LastChild function will return the Last Child member belongs to the specified member. For example, If you know a single customer name and if you want to find the Sales of the Last customer, then you can use this MDX LastChild function.

MDX LastChild Function Syntax

The basic syntax of the LastChild in Multidimensional Expression is as shown below:

Member_Expression.LASTCHILD

Member_Expression: Any Multidimensional Expression that returns valid Member.

For this LastChild function in MDX query, We are going to use the below show data. The following screenshot shows the Countries inside the Geography

MDX LASTCHILD FUNCTION

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

MDX LASTCHILD FUNCTION

MDX LastChild Function Example

In this example, we are going to find the Last Children present in the France Country. It means the Last State present in the France country.

TIP: We can use MDX FirstChild Function to find the First Child Member.

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

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 write the MDX Lastchild member of France from all the State-Provinces present in the France country.

[Geography].[Geography].[Country].[France].LASTCHILD

For Yveline State, there are no sales at all. So, it is displaying Null results.

MDX LastChild Function Example 2

In this example, we are going to find the Last Children present in the Countries list and calculate the Reseller Sales Amount of that.

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

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

[Measures].[Reseller Sales Amount] ON COLUMNS

From Below line of code,

[Geography].[Geography].[Country].[France].PARENT.LASTCHILD

MDX will first implement the Parent function to find the parent member of a France, Who is All Members. Please refer MDX Parent Function for further understanding

Next, It will implement the LastChild function to find the Last child member of the Countries List Who is the United States.

MDX LastChild Function Alternative

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

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