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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
justlogmein
Helper III
Helper III

Create a numbered index column from an indented hierarchy (for BOMs)

I am trying to do the reverse of what many others seem to be trying to do. I have an output of a list of parts that uses spaces to indicate what level they are at under the parent assembly above. I want to add a column that shows this relationship numerically, like I have in the example below.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wck4sUtJRMlSK1YlWUnDNS8/MSwXx9aAiCgGZxSX5eRAhuCBQFC6kZwQTDMrMS4eLGkNE3VMTi5LyK8DCMIUe+aXFMKVGcDNBKqFCQIWxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Part Name" = _t, Output = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Part Name", type text}, {"Output", type text}})
in
    #"Changed Type"
2 REPLIES 2
KeyurPatel14
Responsive Resident
Responsive Resident

hii @justlogmein ,
Can you please provide input in text format and output also so that I can understand the question?

All of the info is already there. The input is an indented list, so there are are a number of spaces until the words, which designate the level. The part's parent part is the one on the previous indentation directly above it. The output column I have included in the M code already above. It is a numbered list which outlines which parents it has come from.

You can see below that the Ring and Pin are under the Piston assembly, which are under the Engine assembly, which are under the Car assembly. And the Housing and Gear are under the Gearbox assembly, which is under the Car assembly. 

Input:

Part Name

Car
 Engine
  Piston
   Pin
   Ring
 Gearbox
  Housing
  Gear

Helpful resources

Announcements
Sept PBI Carousel

Power BI Monthly Update - September 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors