The ultimate Microsoft Fabric, Power BI, Azure AI, and SQL learning event: Join us in Stockholm, September 24-27, 2024.
Save €200 with code MSCUST on top of early bird pricing!
Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started
Hola chicos,
Tengo la siguiente tabla CSV:
Producto de bacalao | Producto |
Categoría | X |
31 | Agua |
Categoría | Y |
41 | bocadillo |
42 | Chocolate |
Categoría | Z |
51 | Arroz |
52 | Frijol |
53 | Ensalada |
Quiero importar esta tabla CSV a Power BI, pero tiene que tener un aspecto similar al siguiente:
Producto de bacalao | Producto | Categoría |
31 | Agua | X |
41 | bocadillo | Y |
42 | Chocoalate | Y |
51 | Arroz | Z |
52 | Frijol | Z |
53 | Ensalada | Z |
¿Alguien puede ayudarme?
obs: no puedo editar la tabla csv original
Solved! Go to Solution.
Esta es una manera de hacerlo en el editor de consultas. Para ver cómo funciona, simplemente cree una consulta en blanco, vaya a Editor avanzado y reemplace el texto allí con el código M a continuación.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wck4sSU3PL6pUUNJRilCK1YlWMjYEMsOBwkVgLkhCAcyCKQUKRIIFTEAqg/MSk7MhXCMg1zkjPzk/J7EEt94osIApSG9QZnIqhAfS6pSamAfhGYPMTcxJTFGKjQUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Cod Product" = _t, Product = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Cod Product", type text}, {"Product", type text}}),
#"Trimmed Text" = Table.TransformColumns(#"Changed Type",{{"Cod Product", Text.Trim, type text}}),
#"Added Custom" = Table.AddColumn(#"Trimmed Text", "Category", each if [Cod Product] = "Category" then [Product] else null),
#"Filled Down" = Table.FillDown(#"Added Custom",{"Category"}),
#"Filtered Rows" = Table.SelectRows(#"Filled Down", each ([Cod Product] <> "" and [Cod Product] <> "Category")),
#"Changed Type1" = Table.TransformColumnTypes(#"Filtered Rows",{{"Category", type text}})
in
#"Changed Type1"
saludos
palmadita
To learn more about Power BI, follow me on Twitter or subscribe on YouTube.
Hola @henriquemalone,
Aquí hay otra manera.
Puede probar esto en Power Query, Advanced Editor
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wck4sSU3PL6pUUNJRilCK1YlWMjYEMsOBwkVgLkhCAcyCKQUKRIIFTEAqg/MSk7MhXCMg1zkjPzk/J7EEt94osIApSG9QZnIqhAfS6pSamAfhGYPMTcxJTFGKjQUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Cod Product" = _t, Product = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Cod Product", type text}, {"Product", type text}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Category", each if Text.Contains(Text.Upper([Cod Product]), "CATEGORY")
then [Product]
else null, type text),
#"Filled Down" = Table.FillDown(#"Added Custom",{"Category"}),
#"Filtered Rows" = Table.SelectRows(#"Filled Down", each not Text.Contains([Cod Product], "Cat") and [Cod Product] <> "" and ([Cod Product] <> " "))
in
#"Filtered Rows"
Espero que esto ayude.
Hola
Este código M funciona
let
Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
#"Filtered Rows" = Table.SelectRows(Source, each ([Cod Product] <> null)),
#"Added Custom" = Table.AddColumn(#"Filtered Rows", "Category", each if [Cod Product] = "Category" then [Product] else null),
#"Filled Down" = Table.FillDown(#"Added Custom",{"Category"}),
#"Added Custom2" = Table.AddColumn(#"Filled Down", "Value", each if [Cod Product]<>"Category" then [Cod Product] else null),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom2",{"Cod Product"}),
#"Filtered Rows1" = Table.SelectRows(#"Removed Columns", each ([Value] <> null)),
#"Reordered Columns" = Table.ReorderColumns(#"Filtered Rows1",{"Category", "Product", "Value"}),
#"Changed Type1" = Table.TransformColumnTypes(#"Reordered Columns",{{"Value", type number}})
in
#"Changed Type1"
Esta es una manera de hacerlo en el editor de consultas. Para ver cómo funciona, simplemente cree una consulta en blanco, vaya a Editor avanzado y reemplace el texto allí con el código M a continuación.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wck4sSU3PL6pUUNJRilCK1YlWMjYEMsOBwkVgLkhCAcyCKQUKRIIFTEAqg/MSk7MhXCMg1zkjPzk/J7EEt94osIApSG9QZnIqhAfS6pSamAfhGYPMTcxJTFGKjQUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Cod Product" = _t, Product = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Cod Product", type text}, {"Product", type text}}),
#"Trimmed Text" = Table.TransformColumns(#"Changed Type",{{"Cod Product", Text.Trim, type text}}),
#"Added Custom" = Table.AddColumn(#"Trimmed Text", "Category", each if [Cod Product] = "Category" then [Product] else null),
#"Filled Down" = Table.FillDown(#"Added Custom",{"Category"}),
#"Filtered Rows" = Table.SelectRows(#"Filled Down", each ([Cod Product] <> "" and [Cod Product] <> "Category")),
#"Changed Type1" = Table.TransformColumnTypes(#"Filtered Rows",{{"Category", type text}})
in
#"Changed Type1"
saludos
palmadita
To learn more about Power BI, follow me on Twitter or subscribe on YouTube.
Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.
Check out the August 2024 Power BI update to learn about new features.