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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Syndicate_Admin
Administrator
Administrator

¿Puede PowerBI hacer esto?

Tengo un conjunto de datos de ejemplo como este

mesvendedorIphone este añoIphone el año pasadoIpad este añoIpad el año pasado
Agobob20153025
AgoEvan40355045

Necesito crear una tabla o matriz como esta

Artículoventa total Agosto de este añocambio en las ventas (este año vs el año pasado)
IPhone60(20+40)-(15+35)
Ipad 80(30+50) - (25+45)

¿Es esto posible? ¡Gracias!

1 ACCEPTED SOLUTION
Syndicate_Admin
Administrator
Administrator

El primer paso es llevar los datos a un formato utilizable.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcixNV9JRSspPApJGBkDC0BRIGINYRqZKsTowFalliXlAygQkYQxSYgpimQCVxAIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [month = _t, salesperson = _t, #"Iphone this year" = _t, #"Iphone last year" = _t, #"Ipad this year" = _t, #"Ipad last year" = _t]),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"month", "salesperson"}, "Attribute", "Value"),
    #"Changed Type" = Table.TransformColumnTypes(#"Unpivoted Other Columns",{{"Value", Currency.Type}}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Changed Type", "Attribute", Splitter.SplitTextByEachDelimiter({" "}, QuoteStyle.Csv, false), {"Attribute.1", "Attribute.2"}),
    #"Renamed Columns" = Table.RenameColumns(#"Split Column by Delimiter",{{"Attribute.1", "Product"}}),
    #"Replaced Value" = Table.ReplaceValue(#"Renamed Columns","this year","2021",Replacer.ReplaceText,{"Attribute.2"}),
    #"Replaced Value1" = Table.ReplaceValue(#"Replaced Value","last year","2020",Replacer.ReplaceText,{"Attribute.2"}),
    #"Added Custom" = Table.AddColumn(#"Replaced Value1", "Date", each Date.FromText([month] & " 1 " & [Attribute.2])),
    #"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"salesperson", "Product", "Value", "Date"})
in
    #"Removed Other Columns"

Rendimientos

lbendlin_0-1631924881838.png

Eso es algo que puede cargar en Power BI.

lbendlin_1-1631925076952.png

Si desea mostrar el cambio, normalmente reste el valor anterior del valor actual. ¿Tu ejemplo parece indicar que quieres calcularlo al revés?

View solution in original post

3 REPLIES 3
Syndicate_Admin
Administrator
Administrator

Hola

En los datos brutos, no debería tener este año y el año pasado. En su lugar, debe tener un año o una fecha como encabezado. Esto nos permitirá utilizar las funciones Date Intellignece.

Syndicate_Admin
Administrator
Administrator

El primer paso es llevar los datos a un formato utilizable.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcixNV9JRSspPApJGBkDC0BRIGINYRqZKsTowFalliXlAygQkYQxSYgpimQCVxAIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [month = _t, salesperson = _t, #"Iphone this year" = _t, #"Iphone last year" = _t, #"Ipad this year" = _t, #"Ipad last year" = _t]),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"month", "salesperson"}, "Attribute", "Value"),
    #"Changed Type" = Table.TransformColumnTypes(#"Unpivoted Other Columns",{{"Value", Currency.Type}}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Changed Type", "Attribute", Splitter.SplitTextByEachDelimiter({" "}, QuoteStyle.Csv, false), {"Attribute.1", "Attribute.2"}),
    #"Renamed Columns" = Table.RenameColumns(#"Split Column by Delimiter",{{"Attribute.1", "Product"}}),
    #"Replaced Value" = Table.ReplaceValue(#"Renamed Columns","this year","2021",Replacer.ReplaceText,{"Attribute.2"}),
    #"Replaced Value1" = Table.ReplaceValue(#"Replaced Value","last year","2020",Replacer.ReplaceText,{"Attribute.2"}),
    #"Added Custom" = Table.AddColumn(#"Replaced Value1", "Date", each Date.FromText([month] & " 1 " & [Attribute.2])),
    #"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"salesperson", "Product", "Value", "Date"})
in
    #"Removed Other Columns"

Rendimientos

lbendlin_0-1631924881838.png

Eso es algo que puede cargar en Power BI.

lbendlin_1-1631925076952.png

Si desea mostrar el cambio, normalmente reste el valor anterior del valor actual. ¿Tu ejemplo parece indicar que quieres calcularlo al revés?

¡Muchas gracias!

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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