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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

Parent Child Merge Calculation

I have a dax code the get the relationship for parent and child 

 

Relation = CONCATENATEX(FILTER('Table',PATHCONTAINS(PATH('Table'[Child],'Table'[Parent]),EARLIER('Table'[Child]))),'Table'[Child],"|")
 
But unable to get the calculate sum values. 
 
Pls. kind support to get the calculated values same as Relation logic. but should be sum calculation.
 Below should be same as the results column values.
 
ChildParentValueRelationResults
2001200210200110
20022003152001|200225
20032004202001|2002|200345
20042005252001|2002|2003|200470
20052006302001|2002|2003|2004|2005100
20062007352001|2002|2003|2004|2005|2006135
20072008402001|2002|2003|2004|2005|2006|2007175
20082009102001|2002|2003|2004|2005|2006|2007|2008185
2009 152001|2002|2003|2004|2005|2006|2007|2008|2009200
2010201120201020
2011 252010|2011|2012|2013|2014|2015|2016245
20122011302012|2013|2014|2015|2016200
2013201235201335
2014201240201440
20152012452015|201695
2016201550201650

 

 

1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

lbendlin_0-1708788820538.png

P is a calculated column

P = path('Table'[Child],'Table'[Parent])

Res is a measure

Res = 
var c = SELECTEDVALUE('Table'[Child])
var a= SUMMARIZE(ALLSELECTED('Table'),[Value],[P])
var b= ADDCOLUMNS(a,"inc",IF(PATHCONTAINS([P],c),[Value]))
return sumx(b,[inc])

View solution in original post

8 REPLIES 8
lbendlin
Super User
Super User

lbendlin_0-1708788820538.png

P is a calculated column

P = path('Table'[Child],'Table'[Parent])

Res is a measure

Res = 
var c = SELECTEDVALUE('Table'[Child])
var a= SUMMARIZE(ALLSELECTED('Table'),[Value],[P])
var b= ADDCOLUMNS(a,"inc",IF(PATHCONTAINS([P],c),[Value]))
return sumx(b,[inc])
Anonymous
Not applicable

@lbendlin , Awesome. It works as expected. Thanks. 

Anonymous
Not applicable

@lbendlin , hi again, i use the same code to count the values

 

ResCount =
var c = SELECTEDVALUE('Table'[Child])
var a= SUMMARIZE(ALLSELECTED('Table'),[Value],[P])
var b= ADDCOLUMNS(a,"inc",IF(PATHCONTAINS([P],c),[Value]))
return COUNTX(b,[inc])
 
can you help me to count only the values that is more than zero or not null values on the column Value. 

Please provide sample data that fully covers your issue.
Please show the expected outcome based on the sample data you provided.

Anonymous
Not applicable

@lbendlin hi again, below should be the output table in column Result_Count and Result_Sum

 

I also have an issue, error showing, if i change the child and parent value as text.

 

Is there's a way that instead of showing in column Relation as Child/Parent as number should be the child/parent name instead. Thanks again.

 

Screenshot 2024-02-25 201959.png

Can you please post in a usable format?  I can't work with screenshots.

Anonymous
Not applicable

@lbendlin , pls. see shared link. 

 

parent-child 

you can get rid of the errors by replacing missing parent names with nulls.

 

I don't understand the logic behind your expected output columns. Please elaborate.

 

 

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.