Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hola a todos - Necesito soporte a través de Power Query para transfrom mis datos como se muestra a continuación:
Esencialmente duplicado de las filas, y convertir el "recuento" a 1
Además, la tabla de datos se agrega debajo de la captura de pantalla.
¡¡Salud!!
Tipo | Enero-20 | Feb-20 | Mar-20 | Abr-20 |
A | 1 | 1 | 2 | 2 |
B | 2 | 2 | 2 | 1 |
C | 1 | 1 | 3 | 3 |
Solved! Go to Solution.
Hola @hackfifi ,
Usted podría probar debajo del código M
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTKEYiMwjtWJVnKC8yDYECzqjKTWGIxjYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Type = _t, #"Jan-20" = _t, #"Feb-20" = _t, #"Mar-20" = _t, #"Apr-20" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Type", type text}, {"Jan-20", Int64.Type}, {"Feb-20", Int64.Type}, {"Mar-20", Int64.Type}, {"Apr-20", Int64.Type}}),
#"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Type"}, "Attribute", "Value"),
#"Added Custom1" = Table.AddColumn(#"Unpivoted Columns", "Custom", each {Number.From(1)..Number.From([Value])}),
#"Expanded Custom" = Table.ExpandListColumn(#"Added Custom1", "Custom"),
#"Pivoted Column" = Table.Pivot(#"Expanded Custom", List.Distinct(#"Expanded Custom"[Attribute]), "Attribute", "Value", List.Count),
#"Removed Columns" = Table.RemoveColumns(#"Pivoted Column",{"Custom"}),
#"Replaced Value" = Table.ReplaceValue(#"Removed Columns",0,null,Replacer.ReplaceValue,{"Jan-20", "Feb-20", "Mar-20", "Apr-20"})
in
#"Replaced Value"
Saludos
Zoe Zhi
Si este post ayuda, entonces considera Aceptarlo como la solución para ayudar a los otros miembros a encontrarlo más rápidamente.
Hola @hackfifi ,,
Creo que esto te llevará allí y luego puedes cambiar el valor a "1" de "2" o "3".
https://community.powerbi.com/t5/Desktop/Create-Duplicate-Entries-based-on-Column-Value/td-p/359228
Proud to be a Datanaut!
Private message me for consulting or training needs.
@collinq compañero de agradecimiento , pero eso no funciona como necesito hacer esto en el POWER QUERY, y la complicación es mi "recuento" está a través de las columnas (es decir, por mes)
Intenté despotablear los datos y hacerlo; pero no hay suerte.
Agradezco su respuesta.
Hola @hackfifi ,
Usted podría probar debajo del código M
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTKEYiMwjtWJVnKC8yDYECzqjKTWGIxjYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Type = _t, #"Jan-20" = _t, #"Feb-20" = _t, #"Mar-20" = _t, #"Apr-20" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Type", type text}, {"Jan-20", Int64.Type}, {"Feb-20", Int64.Type}, {"Mar-20", Int64.Type}, {"Apr-20", Int64.Type}}),
#"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Type"}, "Attribute", "Value"),
#"Added Custom1" = Table.AddColumn(#"Unpivoted Columns", "Custom", each {Number.From(1)..Number.From([Value])}),
#"Expanded Custom" = Table.ExpandListColumn(#"Added Custom1", "Custom"),
#"Pivoted Column" = Table.Pivot(#"Expanded Custom", List.Distinct(#"Expanded Custom"[Attribute]), "Attribute", "Value", List.Count),
#"Removed Columns" = Table.RemoveColumns(#"Pivoted Column",{"Custom"}),
#"Replaced Value" = Table.ReplaceValue(#"Removed Columns",0,null,Replacer.ReplaceValue,{"Jan-20", "Feb-20", "Mar-20", "Apr-20"})
in
#"Replaced Value"
Saludos
Zoe Zhi
Si este post ayuda, entonces considera Aceptarlo como la solución para ayudar a los otros miembros a encontrarlo más rápidamente.
Hola @hackfifi ,
Me he quedado sin tiempo, pero CASI lo tengo. Ya que no voy a volver a esto por aproximadamente 4 días estoy dando lo que tengo en este momento. Hice un despivot y un pivote y obtengo este resultado:
Tipo | 20-Jan | 20-Feb | 20-Mar | 20-Abr | |
A | 1 | 1 | 0 | 0 | |
A | 0 | 0 | 1 | 1 | |
B | 0 | 0 | 0 | 1 | |
B | 1 | 1 | 1 | 0 | |
C | 1 | 1 | 0 | 0 | |
C | 0 | 0 | 1 | 1 | |
Lo que falta es la tercera fila esperada de "C". Me pregunto si ponemos un "recuento" o un campo de índice o algo que podemos agregar al pivote? Avísame cómo va, volveré la semana que pueda.
Construí mi propia tabla de datos para que coincida con su original (o eso creo) por lo que mi fuente y la suya diferirán....
Aquí está el código que usé para llegar allí:
Dejar
Source : Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTKEYiMwjtWJVnKC8yDYECzqjKTWGIxjYwE", BinaryEncoding.Base64), Compression.Deflate)), let _t á ((tipo de texto que acepta valores NULL) meta [Serialized.Text ? true]) en la tabla de tipos [Tipo de _t, "Ene-20" - _t, "Feb-20" - _t, "Mar-20" - _t, "Apr-20" - _t]),
"Tipo cambiado" - Table.TransformColumnTypes(Source, ?"Type", texto de tipo, "Jan-20", Int64.Type, "Feb-20", Int64.Type, "Mar-20", Int64.Type, "Apr-20", Int64.Type, "Apr-20", Int64.Type?),
"Unpivoted Columns" á Table.UnpivotOtherColumns('Changed Type", ''Type"', "Attribute", "Value"),
"Columnas renombradas" - Table.RenameColumns(''Columnas de Unpivoted'",'Atributo', "Mes"'),
"Añadido Personalizado" - Table.AddColumn("Columnas renombradas", "GiveMea1", cada 1),
"Changed Type1" á Table.TransformColumnTypes('Added Custom','GiveMea1',type text'),
"Columna con pivote" - Table.Pivot(-"Changed Type1", List.Distinct(-"Changed Type1"[Month]), "Month", "GiveMea1", List.Count),
"Columnas eliminadas" - Table.RemoveColumns("Columna pivotada","Valor"))
En
"Columnas eliminadas"
Proud to be a Datanaut!
Private message me for consulting or training needs.
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
2 | |
1 | |
1 | |
1 | |
1 |