Data aggregation along hierarchy in treemap

Hello,

I’m trying to build a treemap that needs to calculate ratios along a hierarchy. Specifically, I’m looking to do a margin analysis along a product hierarchy (Manufacturer > Product group > Base product > Variations).

I can calculate the margin on the lowest level in the dataframe, but I’m struggling to get the correct results aggregated along the hierarchy. In other data visualisation tools (e.g. PowerBI), this seems to be solved with measures that get calculated dynamically depending on the navigational state of a graph.

I can’t seem to be able to find a way of doing this in Plotly and doing it on the dataframe doesn’t yield the correct results. I saw the documentation of the ‘transform’ function, but the documentation says it’s deprecated with no suggestion what replaces the functionality.

Thanks,
Danny

My guess is that this sort of calculations are to be done in pandas instead, which could be why plotly decided to deprecate their native transform functionality in v5.