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

See when key Fabric features will launch and what’s already live, all in one place and always up to date. Explore the new Fabric roadmap

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
May PBI 25 Carousel

Power BI Monthly Update - May 2025

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

May 2025 Monthly Update

Fabric Community Update - May 2025

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

Top Solution Authors
Top Kudoed Authors