Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

count child hierarchy based on parent

Hi,

I have created hierarchy structure and count all the child of parent hierarchy.

Diagram:

          1
         /  \
       2     3
      / |\    /\
    4 5 6  7 8
          /\     /\
       9 10  11 12

 

From the above diagram I need if I select parent "2" then I need to count total Number of child below of "2"(Example: 4,5,9,10 and display count as  4. Note: don't select  parent "6" bacause parent "6" has child 9,10) .

 

Table structure:

ProjectkeyParentKeyPathlength
1 11
211|22
311|32
421|2|43
521|2|53
621|2|63
731|3|73
831|3|83
961|2|6|94
1061|2|6|104
1181|3|8|114
1281|3|8|124

 

 

 

2 ACCEPTED SOLUTIONS
v-danhe-msft
Microsoft Employee
Microsoft Employee

Hi @Anonymous,

Based on my test, you could refer to below stpes:

Calculate a calculated column:

Column 3 = PATHITEM('Table1'[Path],2,1)

1.PNG

Create below measure:

Measure 2 = CALCULATE(COUNT(Table1[ParentKey]),FILTER(ALL('Table1'),'Table1'[Column 3]=SELECTEDVALUE('Table1'[ParentKey])&&'Table1'[length]<=3))

Result:

1.PNG

You could also download the pbix file to have a view.

 

Regards,

Daniel He

Community Support Team _ Daniel He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

v-danhe-msft
Microsoft Employee
Microsoft Employee

Hi @Anonymous,

Could you please tell me if your problem has been solved? If it is, could you please mark the helpful replies as Answered to close this topic?

 

Regards,

Daniel He

Community Support Team _ Daniel He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-danhe-msft
Microsoft Employee
Microsoft Employee

Hi @Anonymous,

Could you please tell me if your problem has been solved? If it is, could you please mark the helpful replies as Answered to close this topic?

 

Regards,

Daniel He

Community Support Team _ Daniel He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
v-danhe-msft
Microsoft Employee
Microsoft Employee

Hi @Anonymous,

Based on my test, you could refer to below stpes:

Calculate a calculated column:

Column 3 = PATHITEM('Table1'[Path],2,1)

1.PNG

Create below measure:

Measure 2 = CALCULATE(COUNT(Table1[ParentKey]),FILTER(ALL('Table1'),'Table1'[Column 3]=SELECTEDVALUE('Table1'[ParentKey])&&'Table1'[length]<=3))

Result:

1.PNG

You could also download the pbix file to have a view.

 

Regards,

Daniel He

Community Support Team _ Daniel He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.