Forum Discussion

smartin211's avatar
smartin211
Regular Visitor
1 year ago
Solved

How to create a hierarchy for difficult code format?

I am perplexed on the best way to create a hierarchy out od this Taxonomy code column, can anyone help me? Auto hierarchy does not work for me.
  • v-aatheeque's avatar
    v-aatheeque
    1 year ago

    Hi smartin211 ,
    Thank for the clear explanation.

    You’re trying to build a custom hierarchy from a structured taxonomy code like BH-3500.3400-300 so that:

     

    • BH is the top-level parent
    • BH-3500 is the second-level child
    • And any entries like BH-3500.3400-300 should fall under this BH-3500 in a Power BI matrix visual.

    you can create custom column for the Parent as below : 

    Parent = 
    LEFT([Taxonomy Code], FIND("-", [Taxonomy Code]) - 1)
    

     Then for child :

    Child = 
    VAR FirstPart = LEFT([Taxonomy Code], FIND("-", [Taxonomy Code] & "-") - 1)
    VAR AfterFirstDash = MID([Taxonomy Code], LEN(FirstPart) + 2, LEN([Taxonomy Code]))
    VAR SplitDot = FIND(".", AfterFirstDash & ".", 1)
    RETURN 
    IF(
        SplitDot > 1,
        FirstPart & "-" & LEFT(AfterFirstDash, SplitDot - 1),
        [Taxonomy Code]
    )

     the expected output :

    Hope this helps !!

     

    If this post was helpful, please consider marking Accept as solution to assist other members in finding it more easily.