Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

Create Parent - Sub level Hierarchy from spaces

Hello everyone, I was researching how to solve this problem, but I couldn't solve it ๐Ÿ˜ž
The tasks can contain multiple subtasks. The initial task does not contain spaces. The Sub-tasks are subdivided by multiples of 2 spaces.
E.g


Parentlevel = No space
Sublevel_1 = 2 spaces
Sublevel_2 = 4 spaces
Sublevel_3 = 6 spaces
Sublevel_4 = 8 spaces
Sublevel_5 = 10 spaces

How can I convert this is to a PowerBI hierachy?

 

From this:

 

Activity NameActivity ID
Plan1
  HITOS type1  2
    Hitos A3
      Hito A14
        HA1-A5
        HA1-B6
      Hito A27
      Hito A38
  HITOS type29
    Hitos B10
      Hito B111
        HB1-A12

 

TO this:

 

Activity NameActivity IDID Parent ID
Plan1null
HITOS type121
Hitos A32
Hito A143
HA1-A54
HA1-B64
Hito A273
Hito A383
HITOS type291
Hitos B109
Hito B11110
HB1-A1211
   

 

I share the query to paste in the advanced editor


let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCshJzFPSUTJUitWJVlJQ8PAM8Q9WKKksSFUwBAobQYWBEpkl+cUKjkAxY7gYRFTBEaTSBEkUKO5oqAtSa4oh6gQUNcMwwQgoao4hagwUtcB0GEixJZrDQMYaGqCb4ARymaEhqiOcIE4zNEIRhkpApIyxSoHtMMEwDCxsikWHE8QwM6xSYF1AL8cCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Activity Name" = _t, #"Activity ID" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Activity Name", type text}, {"Activity ID", Int64.Type}})
in
#"Changed Type"

Any ideas?

  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi, thank you for answering! the previous solution did not work for me since it only works for 2 levels... I based on that question to formulate this new one since my English is horrible. thank you so much!

2 Replies

  • v-xiaosun-msft's avatar
    v-xiaosun-msft
    Community Support

    Hi Anonymous ,

     

    According to your description, I suggest that you can create a index column in Power Query. And then create a custom column according to the index to return "Parent ID".

    Please refer to the solution in the link below. 

    Solved: Create Parent-Child Hierarchy from indentations - Microsoft Power BI Community

     

    Best Regards,
    Community Support Team _ xiaosun

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

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi, thank you for answering! the previous solution did not work for me since it only works for 2 levels... I based on that question to formulate this new one since my English is horrible. thank you so much!