Forum Discussion

veikko's avatar
veikko
Frequent Visitor
3 years ago

Calculating costs per Path on hierarchical data

Hello,

I have a million rows of hierarchical data which looks like this:

IDPathLevelCostPathCostCode
11010120 
21|2115110XXX
31|2|322095 
41|2|3|431025 
51|2|3|4|5455 
61|2|3|4|641010YYY
71|2|3|732050 
81|2|3|7|841520 
91|2|3|7|8|9555ZZZ
101|2|3|7|1041010 


PathCost is a calculated column which calculates the costs for every row. Costs are cumulated from every row that contain row's path. This is the code for the PathCost column:

PathCost =
    VAR Id_ = [Id]
    RETURN
        SUMX (
            FILTER (
                COSTS,
                FIND(Id_, COSTS[Path], 1, BLANK()) > 0
            ),
            [Cost]
        )

The problem is that the calculated column is very slow. I narrowed the data to 10,000 rows and it loaded the dax for over 15 minutes. Do you have any suggestions how the code could be optimized? I do not need the costs for every row, only the rows where column Code has a value.

I also tried finding paths inside paths instead of finding id's inside paths. It was not significantly faster.

1 Reply