Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago
Solved

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

 

 

  • 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])

8 Replies

  • 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's avatar
      Anonymous
      Not applicable

      lbendlin , Awesome. It works as expected. Thanks. 

      • Anonymous's avatar
        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.