Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Anonymous
Not applicable

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?

1 ACCEPTED SOLUTION
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!

View solution in original post

2 REPLIES 2
v-xiaosun-msft
Community Support
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
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!

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.