Microsoft Fabric Community Conference 2025, March 31 - April 2, Las Vegas, Nevada. Use code FABINSIDER for a $400 discount.
Register nowGet inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.
Estimados, ¿podrían ayudarme a encontrar una manera de dividir una columna de DEPARTAMENTO en filas?
A partir de esto:
DEPARTAMENTO DE USUARIOS
USER1 a:3:{i:0;i:2;i:1;i:15;i:2;i:18;}
A esto:
DEPARTAMENTO DE USUARIOS
USUARIO1 2
USUARIO1 15
USUARIO1 18
donde a:3 significa que hay 3 departamentos: 2, 15, 18, en consecuencia;
i:0;i:2; - significa primer elemento con Id=2
i:1;i:15; - significa segundo elemento con Id=15
I:2;i:18; - significa 3er elemento con Id=18
El número de departamentos puede ser diferente de una fila a otra.
Para los usuarios sin departamentos se ve como:
a:0:{}
Para usuarios con un solo departamento (Id=2):
a:1:{i:0;i:2;} y así sucesivamente.
¡Cualquier ayuda es apreciada!
¡Gracias de antemano!
Queridos, he encontrado una manera:
1) Transformar por Text.BetweenDelimiters por "{" y "}"
2) Text.Split por ";"
3) Tabla.Expandlist.Column
4) Table.AddIndexColumn
5) filtrar por IsEven[Index] = función verdadera.
Puedes probar mi camino también.
1) Transformar por Text.BetweenDelimiters por "{" y "}"
2) Sustitúyase "i:" por ""
3) Text.Split por ";" por fila
4) Eliminar espacio en blanco por filtro.
4) Añadir un índice y filtrar por Number.Mod().
Código M completo:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCg12DTJU0lFKtDK2qs60MrDOtDICYkMQNoVxLKxrlWJjAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [USER = _t, DEPARTMENT = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"USER", type text}, {"DEPARTMENT", type text}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Text.BetweenDelimiters([DEPARTMENT],"{","}")),
#"Replaced Value" = Table.ReplaceValue(#"Added Custom","i:","",Replacer.ReplaceText,{"Custom"}),
#"Split Column by Delimiter" = Table.ExpandListColumn(Table.TransformColumns(#"Replaced Value", {{"Custom", Splitter.SplitTextByDelimiter(";", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Custom"),
#"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Custom", Int64.Type}}),
#"Filtered Rows" = Table.SelectRows(#"Changed Type1", each ([Custom] <> null)),
#"Added Index" = Table.AddIndexColumn(#"Filtered Rows", "Index", 1, 1, Int64.Type),
#"Filtered Rows1" = Table.SelectRows(#"Added Index", each (Number.Mod([Index],2) = 0)),
#"Removed Columns" = Table.RemoveColumns(#"Filtered Rows1",{"Index", "DEPARTMENT"})
in
#"Removed Columns"
El resultado es el siguiente.
Saludos
Rico Zhou
Si esta publicación ayuda, considere Aceptarlo como la solución para ayudar a los otros miembros a encontrarlo más rápidamente.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code FABINSIDER for a $400 discount!
Check out the February 2025 Power BI update to learn about new features.