In Multidimensional Expression, FirstChild function will return the First Child member belongs to the specified member. For example, If you know single customer name and if you want to find the Sales of a first customer then you can use this FirstChild function.
TIP: We can use MDX LastChild Function to find the Last Child Member.
MDX FirstChild Function Syntax
The basic syntax of the MDX FirstChild is:
Member_Expression.FIRSTCHILD
Member_Expression: Any Multidimensional Expression that returns valid Member.
In this article we will show you, How to write FirstChild 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 FirstChild Function Example
In this example we are going to find the First Children present in the France Country. It means first state present in the France country.
CODE
SELECT
[Measures].[Reseller Sales Amount] ON COLUMNS,
[Geography].[Geography].[Country].[France].FIRSTCHILD 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 write the first child member of the France from all the State-Provices present in the France country.
[Geography].[Geography].[Country].[France].FIRSTCHILD
MDX FirstChild Function Example 2
As we all know Paris is one of the state in France and our intention is to find the first state present in France then, we can use this FirstChild function. In this example we are going to find the First 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].[Seine (Paris)].PARENT.FIRSTCHILD 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
From Below line of code,
[Geography].[Geography].[State-Province].[Seine (Paris)].PARENT.FIRSTCHILD
MDX will first implement the Parent function to find the parent member of a [Seine (Paris)], Which is France. Please refer MDX Parent Function for further understanding
Next, It will implement FirstChild function to find the first child member of the France Country, Which is Charente-Maritime. For Charente-Maritime State, there is no sales at all so, it is displaying Null results.
TIP: We can use MDX LastChild Function to find the Last Child Member.
MDX FirstChild Function Syntax
The basic syntax of the MDX FirstChild is:
Member_Expression.FIRSTCHILD
Member_Expression: Any Multidimensional Expression that returns valid Member.
In this article we will show you, How to write FirstChild 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 FirstChild Function Example
In this example we are going to find the First Children present in the France Country. It means first state present in the France country.
CODE
SELECT
[Measures].[Reseller Sales Amount] ON COLUMNS,
[Geography].[Geography].[Country].[France].FIRSTCHILD 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 write the first child member of the France from all the State-Provices present in the France country.
[Geography].[Geography].[Country].[France].FIRSTCHILD
MDX FirstChild Function Example 2
As we all know Paris is one of the state in France and our intention is to find the first state present in France then, we can use this FirstChild function. In this example we are going to find the First 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].[Seine (Paris)].PARENT.FIRSTCHILD 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
From Below line of code,
[Geography].[Geography].[State-Province].[Seine (Paris)].PARENT.FIRSTCHILD
MDX will first implement the Parent function to find the parent member of a [Seine (Paris)], Which is France. Please refer MDX Parent Function for further understanding
Next, It will implement FirstChild function to find the first child member of the France Country, Which is Charente-Maritime. For Charente-Maritime State, there is no sales at all so, it is displaying Null results.
MDX FirstChild Function Alternative
In this example we are going to use the FirstChild function alternative to achieve the same result. Please refer MDX FirstSibling Function to understand the FirstSibling function.
CODE
SELECT
[Measures].[Reseller Sales Amount] ON COLUMNS,
[Geography].[Geography].[State-Province].[Seine (Paris)].FIRSTSIBLING ON ROWS
FROM [Adventure Works];
OUTPUT
In this example we are going to use the FirstChild function alternative to achieve the same result. Please refer MDX FirstSibling Function to understand the FirstSibling function.
CODE
SELECT
[Measures].[Reseller Sales Amount] ON COLUMNS,
[Geography].[Geography].[State-Province].[Seine (Paris)].FIRSTSIBLING ON ROWS
FROM [Adventure Works];
OUTPUT