Forum Discussion
Aerobat
5 years agoFrequent Visitor
Extracting a hierarchy from a range
I already posted a similar problem wher I got some fine help from this amazing community. Now I have developed things a bit further and need to extract the hierarchy from a range and the value a me...
Aerobat
5 years agoFrequent Visitor
Nobody?
ziying35
5 years agoImpactful Individual
Hi, Aerobat
There are some discrepancies between my code and the simulated data you provided, my code runs as shown below:
- Aerobat5 years agoFrequent Visitor
It looks like you are correct!
Can you provide your code?
- Aerobat5 years agoFrequent Visitor
Did you have the code that gave the result above?
- shaowu4595 years agoResolver II
Please make it clear of what is your expected result, my code generates a table like you provided in post #1.
let Source = Excel.CurrentWorkbook(){[Name="data"]}[Content], A = Table.AddColumn(Source,"m",each let a=Table.ToRows(Table.SelectRows(Table.FirstN(Source,List.PositionOf(Source[Name],[Name])),(x)=>x[Range]<>null)), b=List.Transform(a,(y)=>if [Number]<=y{2} and [Number]>=y{1} then List.RemoveRange(y,2,1) else {}) in List.RemoveRange(Record.ToList(_),2,1)&List.Combine(b) ) in Table.FromList(A[m],each _,List.Count(List.Last(A[m]))) - ziying355 years agoImpactful Individual
let Source = Table.FromRecords(Json.Document(Binary.Decompress(Binary.FromText("fZCxDsIgEEB/xdxMEzgOle6OdtDROLSxMQ5l0HQy/rulSQ13FZYOR9/jHpc3NO3QQw3H9hEMKGjGoeufUButtYJDuIVl4L1XcGrDPf4ej6s4go/6OV5jxxUoFPNgUWwEigy1ErUF1DKUJEo5NEan16KMRhYdjytcRxNTGKGYB7nNHUNRoqX32jLUSjT7XjHaFqOd1jKaVtG7VEEymkrRe4bKaMpGx82puDmuN5++qeM8dj5VGCcU8+Dv9RNqNGedZB1jr18=", BinaryEncoding.Base64),Compression.Deflate))), fnTrans = (x,y)=> let ft= Table.RemoveLastN(Table.RemoveColumns(Table.SelectRows(filter, each [Number]<= x and [Endnumber] >=x), "Endnumber"), (r)=>r[Name]=y), fv=Table.FirstValue(ft)=y, cmb=if fv then {} else List.Combine(Table.ToRows(ft)) in cmb, filter = Table.Buffer(Table.SelectRows(Source, each Text.StartsWith([Name], "M"))), trans = Table.AddColumn(Table.RemoveColumns(Source, "Endnumber"), "t", each fnTrans([Number], [Name])), meg = Table.CombineColumns(trans, Table.ColumnNames(trans), each List.RemoveLastN(_)&_{3}, "t")[t], result = let zip=List.Zip(meg), fd={"Name", "Number", "Range"}& List.TransformMany( {1..(List.Count(zip)-3)/3}, each {"Parent lvl", "Number lvl", "Range lvl"}, (x,y)=>y&Text.From(x) ), tbl=Table.FromColumns(zip, fd) in tbl in result- Aerobat5 years agoFrequent Visitor
Hi,
this row:
filter = Table.Buffer(Table.SelectRows(Source, each Text.StartsWith([Name], "M"))),
It assumes headlines starts with "M", but it can start with any letter.