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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
veikko
Frequent Visitor

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 1
v-tangjie-msft
Community Support
Community Support

Hi @veikko ,

 

Please try using a measure instead of calculated column and then output them as tabular visuals.

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

For more information about DAX optimization, you can refer to:

Performance Tuning DAX - Part 1 - Microsoft Power BI Community

DAX Best Practices | MAQ Software Insights

 

Best Regards,

Neeko Tang

If this post  helps, then please consider  Accept it as the solution  to help the other members find it more quickly. 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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