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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

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
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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