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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
ak77
Post Patron
Post Patron

get all child nodes count

Hi All

I have a db model as below 

parent 101 has 3 child (102,103, 104), 102, has 2 ,103 has 1 and 104 has 1

i need a column or a measure 'child count' where i should get all child counts of a parent : 7

Is this possible?

ak77_0-1727370147957.png

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @ak77 

 

I think I understand what you need. In your case, the number of descendants of 101 should return 7, 102 returns 2, and 103 and 104 return 1. You need a measure to get these results.

 

Please follow below steps, i hope it helps.

1. Create a new table to store all parents and use the new table parent field as a slicer.

Note: Do not create a relationship between this new table and your data table.

 

Parent Selection = DISTINCT('Table'[parent])

 

 2. Create a measure with the follow DAX:

 

TotalChildCount = 
VAR CurrentParent = SELECTEDVALUE('Parent Selection'[parent])
VAR CurrentChild = CALCULATETABLE(VALUES('Table'[child]), 'Table'[parent] = CurrentParent)
VAR ChildCount =
CALCULATE(
    COUNTROWS(
    FILTER(
        'Table',
        'Table'[parent] = CurrentParent
    )
    )
)
VAR GrandChildCount =
CALCULATE(
    COUNTROWS(
    FILTER(
        'Table',
        'Table'[parent] IN CurrentChild
    )
    )
)
RETURN
ChildCount + GrandChildCount

 

 

Here is my test result:

vxianjtanmsft_0-1727678956805.pngvxianjtanmsft_1-1727678996486.png

 

 

 Best Regards,
Jarvis Tang
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

3 REPLIES 3
Anonymous
Not applicable

Hi @ak77 

 

I think I understand what you need. In your case, the number of descendants of 101 should return 7, 102 returns 2, and 103 and 104 return 1. You need a measure to get these results.

 

Please follow below steps, i hope it helps.

1. Create a new table to store all parents and use the new table parent field as a slicer.

Note: Do not create a relationship between this new table and your data table.

 

Parent Selection = DISTINCT('Table'[parent])

 

 2. Create a measure with the follow DAX:

 

TotalChildCount = 
VAR CurrentParent = SELECTEDVALUE('Parent Selection'[parent])
VAR CurrentChild = CALCULATETABLE(VALUES('Table'[child]), 'Table'[parent] = CurrentParent)
VAR ChildCount =
CALCULATE(
    COUNTROWS(
    FILTER(
        'Table',
        'Table'[parent] = CurrentParent
    )
    )
)
VAR GrandChildCount =
CALCULATE(
    COUNTROWS(
    FILTER(
        'Table',
        'Table'[parent] IN CurrentChild
    )
    )
)
RETURN
ChildCount + GrandChildCount

 

 

Here is my test result:

vxianjtanmsft_0-1727678956805.pngvxianjtanmsft_1-1727678996486.png

 

 

 Best Regards,
Jarvis Tang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

ak77
Post Patron
Post Patron

hi Thanks for reply. i need all the child , grand child of a parent..there are 10 parents .. how will the calculation work for each parent to get child and its grand child. Please let me know

parry2k
Super User
Super User

@ak77 why not simple row count would work until I'm missing something;

 

Count = COUNTROWS ( Table )


Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors