|
递归函数的形式从来都是很简洁,统一的,把下一次引用的逻辑想清楚就行。
- let
- fx = (sup as text, hierarchy as list) as nullable list =>
- let
- pos = List.PositionOf(Sub, sup, Occurrence.First)
- in if pos>-1 then @fx(Sup{pos}, {sup} & hierarchy) else {sup} & hierarchy,
-
- Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcvdV0lFyVIrViQaSOkpOcJYLnOUGZjkBWc5wliuY5QJkuSvFxgIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [上级 = _t, 下属 = _t]),
- Sup = Source[上级],
- Sub = Source[下属],
- #"Added Column" = Table.AddColumn(Source, "Hierarchy", each fx([上级], {[下属]})),
- Summary = Table.Combine(List.Transform(#"Added Column"[Hierarchy], each Table.FromRows({_})))
- in
- Summary
复制代码
|
|