Advance your Data & AI career with 50 days of live learning, dataviz contests, hands-on challenges, study groups & certifications and more!
Get registeredGet Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more
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?
Solved! Go to Solution.
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:
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.
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:
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.
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
@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.
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!
Check out the October 2025 Power BI update to learn about new features.