Forum Discussion

Rahul_Nair's avatar
Rahul_Nair
Regular Visitor
3 months ago
Solved

Power BI – “Sort by column” error in calculated hierarchy (duplicate labels across hierarchy levels)

Hi everyone, I’m facing an issue with sorting hierarchy levels in Power BI and would appreciate some guidance on the correct approach. I have a hierarchy table that is used in a matrix visual. The ...
  • stoic-harsh's avatar
    3 months ago

    Hey Rahul_Nair,

     

    Laying out the problem statement:

    Power BI requires a one-to-one mapping between the displayed value and the sort value. In your hierarchy, the same label (Admin) exists under multiple parents with different sort orders:

    Level_03Sort_Order
    Admin1
    Admin7

     

    In the correct modeling approach, the hierarchy should be based on unique node identifiers. So, the hierarchy internally would look like:

    Node_IdParent_Node_IdLabelSort_Order
    Fin_AdminFinanceAdmin1
    HR_AdminHRAdmin7

    Then:

    • PATH() could use Node_ID and Parent_Node_ID

    • PATHITEM() would return Node_IDs

    • Use labels as display/descriptive attribute

    • And sort on the unique node-level column

    Implementation:

    Hierarchy_Path =
    PATH ( Table[Node_ID], Table[Parent_Node_ID] )
    Level_03_Node =
    PATHITEM ( Table[Hierarchy_Path], 3 )
    Level_03_Label =
    LOOKUPVALUE (
        DIM_HEADER[Description],
        DIM_HEADER[Node_ID],
        Table[Level_03_Node]
    )

    Then configure:

    Level_03_Node
        Sort by -> Level_03_Sort

    and use the label column only for display purposes.

    It became too long while writing. Apologies.

    Hope this helps!

    Best,

    Harshit