Forum Discussion

J94's avatar
J94
Advocate II
1 year ago
Solved

Measure filter certain levels from different columns

Hi all,    I have a dataset with products with several components. I want to calculate the number of SKU for each product. Unfortunately, there are double values. The product is a car. So level 0 i...
  • lbendlin's avatar
    lbendlin
    1 year ago

    Yes, I see

    That's a rather interesting hierarchy - aka a multi parent hierarchy. Not overly surprising since you mentioned a BOM scenario, but still requires special attention. Usually it is done by "cloning" the child. 

     

    In your case we need to change the logic to only include items that do NOT appear anywhere earlier in the path.

     

    CleanPath = 
    var l = PATHLENGTH([BillOfMaterials_bk])
    var a = ADDCOLUMNS(GENERATESERIES(1,l),"pi",pathitem([BillOfMaterials_bk],[Value]))
    return CONCATENATEX(filter(a,[pi]<>""),[pi],"|")
    
    LastChild = PATHITEMREVERSE([CleanPath],1)
    
    LastOccurrences = 
    var c = [LastChild]
    var a = filter(ALL('Table'),PATHCONTAINS([CleanPath],c) && PATHITEMREVERSE([CleanPath],1)<>c)
    return if(countrows(a)>0,0,1)