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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

DAX - Measure to get Count of child Id's for a given Parent

Hello Team,

 

We have a DB table with following fields, that have Parent-Child hierarchy. 

Source TableSource TableOur reporting requirement is to come up with following tabular visualization, to display only parent Id Categories (C1,C2,C3) with count of child_id’s associated to my Parent. Something as follows:  

Final OutputFinal Output

So, when I select Id -1, the measure should provide the count of child_id’s for it, which is 2 in this case.

I’m SQL guy and very new to DAX, this can be done using a self-join for Id to ParentId in SQL.

Can anyone please provide a DAX expression for the same?

 

Thanks,
Sundeep

1 ACCEPTED SOLUTION
Zubair_Muhammad
Community Champion
Community Champion

hi @Anonymous 

 

Try this method

 

First a calculated column

 

PATH =
PATHITEM ( PATH ( TableName[Id], TableName[ParentId] ), 1, INTEGER )
Now this MEASURE
 
No. of Children =
VAR myvalue =
    SELECTEDVALUE ( TableName[Id] )
VAR mycategory =
    SELECTEDVALUE ( TableName[Category] )
RETURN
    CALCULATE (
        COUNT ( TableName[PATH] ),
        TableName[PATH] = myvalue,
        TableName[Category] <> mycategory,
        ALL ( TableName )
    )

View solution in original post

3 REPLIES 3
Zubair_Muhammad
Community Champion
Community Champion

@Anonymous 

 

Please see attached file as well with your sample data and results

 

Zubair_Muhammad
Community Champion
Community Champion

hi @Anonymous 

 

Try this method

 

First a calculated column

 

PATH =
PATHITEM ( PATH ( TableName[Id], TableName[ParentId] ), 1, INTEGER )
Now this MEASURE
 
No. of Children =
VAR myvalue =
    SELECTEDVALUE ( TableName[Id] )
VAR mycategory =
    SELECTEDVALUE ( TableName[Category] )
RETURN
    CALCULATE (
        COUNT ( TableName[PATH] ),
        TableName[PATH] = myvalue,
        TableName[Category] <> mycategory,
        ALL ( TableName )
    )
Anonymous
Not applicable

Thank you Zubair, this worked. Thanks a bunch for attaching the sample report as well.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 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.