Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

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.

Reply
v-srekom
Employee
Employee

Cómo hacer un conjunto de 2 filas como una sola fila con varias columnas

Hola equipo,

Como soy nuevo en power bi, jst jugando con el editor de consultas para transformar los datos.

Me quedé en 1 escenario que es el siguiente:

v-srekom_0-1602616809389.png

Necesita Rango, Título, LifeTime Gross, Año como 4 columnas y necesita obtener los valores correspondientes correctamente.

Gracias de antemano!

1 ACCEPTED SOLUTION
CNENFRNL
Community Champion
Community Champion

Hola, @v-srekom , hay al menos 2 soluciones, es posible que desee elegir una con la que se sienta más cómodo,

  1. utilizar PQ para descargar el gráfico de taquilla conectándose a
    https://www.boxofficemojo.com/chart/top_lifetime_gross/?area=XWW 😂
  2. pls probar el código de abajo,

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Lc0xD8IgEAXgv9Lc3OGgLfTcHBoXJ+NiCAPRsyG2NAHi75eA4733vZwxcHPhAz3cfd4YbG/g6t+c/c7dJR4plerBLtZGlOP85bByTKduCa/V7W0jNekZcVJjIRIFtbR6l//zgnAcCElWhA0N7bkL/tmUoEkomhWVQhBpsPYH", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t]),

    //core steps of solution  -->
    #"Added Index" = Table.AddIndexColumn(Source, "Index", 0, 1, Int64.Type),
    #"Integer-Divided Column" = Table.TransformColumns(#"Added Index", {{"Index", each Number.IntegerDivide(_, 2), Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Integer-Divided Column", {"Index"}, {{"Grouped", each _}}),
    trf = Table.TransformColumns(#"Grouped Rows", {"Grouped", each List.Combine({[Column1], [Column2]})}),
    //
    
    #"Removed Columns" = Table.RemoveColumns(trf,{"Index"}),
    #"Extracted Values" = Table.TransformColumns(#"Removed Columns", {"Grouped", each Text.Combine(List.Transform(_, Text.From), "#(tab)"), type text}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Extracted Values", "Grouped", Splitter.SplitTextByDelimiter("#(tab)", QuoteStyle.Csv), {"Grouped.1", "Grouped.2", "Grouped.3", "Grouped.4"}),
    #"Promoted Headers" = Table.PromoteHeaders(#"Split Column by Delimiter", [PromoteAllScalars=true]),
    #"Reordered Columns" = Table.ReorderColumns(#"Promoted Headers",{"Rank", "Title", "Lifetime Gross", "Year"})
in
    #"Reordered Columns"

Screenshot 2020-10-13 220534.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

View solution in original post

1 REPLY 1
CNENFRNL
Community Champion
Community Champion

Hola, @v-srekom , hay al menos 2 soluciones, es posible que desee elegir una con la que se sienta más cómodo,

  1. utilizar PQ para descargar el gráfico de taquilla conectándose a
    https://www.boxofficemojo.com/chart/top_lifetime_gross/?area=XWW 😂
  2. pls probar el código de abajo,

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Lc0xD8IgEAXgv9Lc3OGgLfTcHBoXJ+NiCAPRsyG2NAHi75eA4733vZwxcHPhAz3cfd4YbG/g6t+c/c7dJR4plerBLtZGlOP85bByTKduCa/V7W0jNekZcVJjIRIFtbR6l//zgnAcCElWhA0N7bkL/tmUoEkomhWVQhBpsPYH", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t]),

    //core steps of solution  -->
    #"Added Index" = Table.AddIndexColumn(Source, "Index", 0, 1, Int64.Type),
    #"Integer-Divided Column" = Table.TransformColumns(#"Added Index", {{"Index", each Number.IntegerDivide(_, 2), Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Integer-Divided Column", {"Index"}, {{"Grouped", each _}}),
    trf = Table.TransformColumns(#"Grouped Rows", {"Grouped", each List.Combine({[Column1], [Column2]})}),
    //
    
    #"Removed Columns" = Table.RemoveColumns(trf,{"Index"}),
    #"Extracted Values" = Table.TransformColumns(#"Removed Columns", {"Grouped", each Text.Combine(List.Transform(_, Text.From), "#(tab)"), type text}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Extracted Values", "Grouped", Splitter.SplitTextByDelimiter("#(tab)", QuoteStyle.Csv), {"Grouped.1", "Grouped.2", "Grouped.3", "Grouped.4"}),
    #"Promoted Headers" = Table.PromoteHeaders(#"Split Column by Delimiter", [PromoteAllScalars=true]),
    #"Reordered Columns" = Table.ReorderColumns(#"Promoted Headers",{"Rank", "Title", "Lifetime Gross", "Year"})
in
    #"Reordered Columns"

Screenshot 2020-10-13 220534.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.