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

Problemas con la transposición

Hola a todos,

Estoy tratando de transponer mis datos sin procesar y obtenerlos en un formato específico. Necesito transponer los datos sin procesar para que el SKU del sitio web esté al principio de la fila, seguido de la suma de la cantidad del componente. Luego, cualquiera que sea el número en el campo Cantidad de componentes, enumere el UPC y las dimensiones muchas veces hasta que se contabilicen todas.

¡Gracias de antemano!

DATOS BRUTOS
SKU del sitio webCantidad de componentesPeso del componente (lbs)Altura del componente (in)Longitud del componente (in)Ancho del componente (entrada)UPCRecuento de cajas
AB-CD-DD-123424489008100993822974
AB-CD-DD-1234136133222008100993821814
AB-CD-DD-123411096008100993826004
ZXY-FHR-6424213103008100993811085
ZXY-FHR-642411096008100993800265
ZXY-FHR-642411993023008100478692835
ZXY-FHR-6424161183131008100478693205
FORMATO NECESARIO
vendor_skunumber_of_boxesbox_1_upcshipping_weight1package_height1package_length1package_width1box_2_upcshipping_weight1package_height1package_length1package_width1box_3_upcshipping_weight1package_height1package_length1package_width1box_4_upcshipping_weight1package_height1package_length1package_width1box_5_upcshipping_weight1package_height1package_length1package_width1
AB-CD-DD-123440081009938229744890081009938229744890081009938218136133222008100993826001096
ZXY-FHR-64245008100993811081310300810099381108131030081009938002610960081004786928319930230081004786932061183131
3 REPLIES 3
Syndicate_Admin
Administrator
Administrator

Puede abrir el 'Editor avanzado' para acceder al código.

jgeddes_0-1685646828732.png

El código que proporcioné contiene el origen de datos que introduje manualmente. Tendrás que poner tu fuente en lugar de eso. Siempre que su fuente tenga los mismos nombres de columna que el ejemplo que proporcionó, puede cambiar la línea de origen. Si su tabla real tiene nombres de columna diferentes, deberá cambiar el código para reflejar los nombres reales.

Syndicate_Admin
Administrator
Administrator

@jgeddes ¡Gracias! Pregunta tonta. ¿Dónde puedo introducir este código cuando estoy en la consulta de energía?

Syndicate_Admin
Administrator
Administrator

Esto se puede hacer en Power Query con el siguiente código.
Aquí tienes...

let
Source =
Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("fY9BDsIwDAT/0nMjre3gOkcgQpw5AVX//w3ikFIqUA6TrBSN15nn4XgK5xxyDsQSh3HgQmxYIRUAIyAlMeY01cdl/FWpIOpBPPkk5r1ORl3dQWvVvarAR33eH+FyvQWNvO5cy/1GC5tKBP/J4Z/aLwVYu2ZqmrjPW22cTBOb9GStE3wzofX4soXxtpcX", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Website Sku" = _t, #"Component Qty" = _t, #"Component Weight (Lbs)" = _t, #"Component Height (in)" = _t, #"Component Length (in)" = _t, #"Component Width (in)" = _t, UPC = _t, #"Box Count " = _t]),
#"Changed Type" =
Table.TransformColumnTypes(
Source,
{{"Website Sku", type text}, {"Component Qty", Int64.Type}, {"Component Weight (Lbs)", Int64.Type}, {"Component Height (in)", Int64.Type}, {"Component Length (in)", Int64.Type}, {"Component Width (in)", Int64.Type}, {"UPC", type text}, {"Box Count ", Int64.Type}}),
addAdditionalRowColumn =
Table.AddColumn(
#"Changed Type",
"addRowColumn",
each if [Component Qty] > 1
then "1" & Text.Repeat("-1", [Component Qty] - 1)
else [Component Qty]
),
addRows =
Table.ExpandListColumn(
Table.TransformColumns(
Table.TransformColumnTypes(
addAdditionalRowColumn,
{{"addRowColumn", type text}}, "en-US"
),
{{"addRowColumn", Splitter.SplitTextByDelimiter("-", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}
),
"addRowColumn"
),
#"Changed Type1" =
Table.TransformColumnTypes(
addRows,
{{"addRowColumn", Int64.Type}}
),
#"Removed Columns" =
Table.RemoveColumns(
#"Changed Type1",
{"Component Qty"}
),
#"Reordered Columns" =
Table.ReorderColumns(
#"Removed Columns",
{"Website Sku", "Box Count ", "UPC", "Component Weight (Lbs)", "Component Height (in)", "Component Length (in)", "Component Width (in)", "addRowColumn"}
),
#"Unpivoted Other Columns" =
Table.UnpivotOtherColumns(
#"Reordered Columns",
{"Website Sku", "Box Count "},
"Attribute",
"Value"
),
#"Grouped Rows" =
Table.Group(
#"Unpivoted Other Columns",
{"Website Sku", "Box Count "},
{{"groupedSKUs", each _, type table [Website Sku=nullable text, #"Box Count "=nullable number, Attribute=text, Value=number]}}
),
transformTable =
Table.AddColumn(
#"Grouped Rows",
"selectedColumns",
each Table.PromoteHeaders(
Table.Transpose(
Table.SelectRows(
Table.SelectColumns(
[groupedSKUs],
{"Attribute", "Value"}
),
each [Attribute] <> "addRowColumn"
)
)
)
),
#"Removed Columns1" =
Table.RemoveColumns(
transformTable,
{"groupedSKUs"}
),
getListOfColumnNames =
Table.ColumnNames(
Table.Combine(
#"Removed Columns1"[selectedColumns]
)
),
#"Converted to Table" =
Table.FromList(
getListOfColumnNames,
Splitter.SplitByNothing(),
null,
null,
ExtraValues.Error
),
extractTextAfterDelimiter =
Table.AddColumn(
#"Converted to Table",
"Text After Delimiter",
each Text.AfterDelimiter([Column1], "_"),
type text
),
determineUPCNumber =
Table.AddColumn(
extractTextAfterDelimiter,
"Custom",
each if Number.Mod(Number.From([Text After Delimiter]),5) = 0
then Number.IntegerDivide(Number.From([Text After Delimiter]),5) - 1
else Number.IntegerDivide(Number.From([Text After Delimiter]),5)
),
constructNewName =
Table.AddColumn(
determineUPCNumber,
"newName",
each if [Custom] = null
then Text.BeforeDelimiter([Column1], "_") & "_1"
else Text.BeforeDelimiter([Column1], "_") & "_" & Number.ToText([Custom] + 2)
),
#"Removed Columns2" =
Table.RemoveColumns(
constructNewName,
{"Text After Delimiter", "Custom"}
),
createRenamingList =
List.Zip(
{#"Removed Columns2"[Column1], #"Removed Columns2"[newName]}
),
expandTransformedTable =
Table.ExpandTableColumn(
#"Removed Columns1",
"selectedColumns",
getListOfColumnNames
),
#"Renamed Columns" =
Table.RenameColumns(expandTransformedTable, createRenamingList)
in
#"Renamed Columns"

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

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

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

Top Solution Authors