Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.
Necesito ayuda: Quiero crear una columna "Resultado" que tenga el elemento principal junto con su elemento componente. Si esto no es un problema recursivo, por favor hágame saber qué tipo de sintaxis debo buscar en google para resolver esto.
Gracias por cualquier ayuda de antemano
Hi, @kk1791 ;
Aquí hay dos métodos en power query.
1.Agrupar por columna.
2.añadir columna condicional.
3.unpivot.
El espectáculo final:
M lanuage:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQwMFTSUTIyMjEwANKGSrE6GIJG2ASNsQmaoApaYjPTEpuZltjMtMRtpqlSbCwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"End Item" = _t, #"PARENT ITEM" = _t, #"COMPONENT ITEM" = _t]),
#"Grouped Rows" = Table.Group(Source, {"PARENT ITEM", "End Item"}, {{"min", each List.Min([COMPONENT ITEM]), type nullable text}, {"a", each _, type table [End Item=nullable text, PARENT ITEM=nullable text, COMPONENT ITEM=nullable text]}}),
#"Expanded a" = Table.ExpandTableColumn(#"Grouped Rows", "a", {"COMPONENT ITEM"}, {"a.COMPONENT ITEM"}),
#"Added Conditional Column" = Table.AddColumn(#"Expanded a", "Custom", each if [min] = [a.COMPONENT ITEM] then [PARENT ITEM] else null),
#"Removed Columns" = Table.RemoveColumns(#"Added Conditional Column",{"min", "PARENT ITEM"}),
#"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"End Item", "Custom", "a.COMPONENT ITEM"}),
#"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Reordered Columns", {"End Item"}, "Attribute", "Value"),
#"Removed Columns1" = Table.RemoveColumns(#"Unpivoted Columns",{"Attribute"})
in
#"Removed Columns1"
Método2:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQwMFTSUTIyMjEwANKGSrE6GIJG2ASNsQmaoApaYjPTEpuZltjMtMRtpqlSbCwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"End Item" = _t, #"PARENT ITEM" = _t, #"COMPONENT ITEM" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"End Item", Int64.Type}, {"PARENT ITEM", Int64.Type}, {"COMPONENT ITEM", Int64.Type}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each let a = [PARENT ITEM],
Component = Table.SelectRows(#"Changed Type",each [PARENT ITEM] = a)[COMPONENT ITEM]
in List.Combine({ List.Distinct({[PARENT ITEM]}) ,Component})),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"COMPONENT ITEM"}),
#"Grouped Rows" = Table.Group(#"Removed Columns", {"End Item", "PARENT ITEM"}, {{"Count", each List.First([Custom]), type list}}),
#"Expanded Count" = Table.ExpandListColumn(#"Grouped Rows", "Count"),
#"Removed Columns1" = Table.RemoveColumns(#"Expanded Count",{"PARENT ITEM"})
in
#"Removed Columns1"
Saludos
Equipo de soporte de la comunidad _ Yalan Wu
Si esta publicación ayuda, considere Aceptarla como la solución para ayudar a los otros miembros a encontrarla más rápidamente.