Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago
Solved

Matrix with multiple hierarchy

Hello,

 

I have a table that contains father_code and for each one of them there is a son code(it's like category and subcategory).

In parallel with, i have a corresponding label that corresponds to heach category. (It's like having Cateogry and subcategory and with it color and subcolor).

 

Note: The son code here is the first element as there is no father code for it.

 

Here is my table: 

Son_codeFather_codeLabel
A 1
BA3
HA2
EA4
FA5
CB6
DB7

 

I tried using matrix to visualize the data but it does not work with double hiearchies as the first son code is not the real son code but the father code.

 

Here is a formatted table to understand the problem and how the output should show: 

 CODELABEL
+A1
-A|H1|2
-A|B1|3
-A|F1|5
-A|E1|4
-A|B|C1 | 3 | 6
-A|B|D1|3 | 7

 

If you have any idea on that either matrix or using DAX to format that.

 

Thank you in advance,

Salem

4 Replies

  • Wilson_'s avatar
    Wilson_
    Memorable Member

    Hey salemhaddad,

     

    Look into the PATH DAX function. Here's a link to some documentation. It seems to be exactly what you need.


    ----------------------------------
    If this post helps, please consider accepting it as the solution to help other members find it quickly. Also, don't forget to hit that thumbs up and subscribe! (Oh, uh, wrong platform?)

     

    P.S. Need a more in-depth consultation for your Power BI data modeling or DAX issues? Feel free to hire me on Upwork or DM me directly on here! I would love to clear up your Power BI headaches.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Thank you very much for the recommandation.

     

    I tried to use it: 

    DEFINE
      VAR path_column = PATH(table[Son_code], table[Father_code])
     
      EVALUATE
        SELECTCOLUMNS(table,table[Son_code], table[Father_code], 
    "path_column", path_column
    )
     
    It give an error: A table of multiple values was supplied where a single value was expected.