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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
MARRASARG1974
Frequent Visitor

Agregar automaticamente columnas como valores de registro haya en los valores de un campo

Hola, tengo la siguiente tabla:

NIVELDESCRIPCIONCANTIDAD
1A10
2B15
3C20
1D12
2E14
3F15

Y quisiera que mediante un loop o alguna forma automatica me agregue columnas como valores de niveles haya quedando de la siguiente manera:

NIVELDESCRIPCIONNIVEL1NIVEL2NIVEL3CANTIDAD
1AA  10
2B B 15
3C  C20
1DD  12
2E E 14
3F  F15
1 ACCEPTED SOLUTION
v-jingzhan-msft
Community Support
Community Support

Hi @MARRASARG1974 

 

Here is my solution. Steps:

1. Duplicate NIVEL column and DESCRIPCION column.

2. Add prefix string "NIVEL" to [NIVEL - Copy] column. 

3. Pivot [NIVEL - Copy] column and select [DESCRIPCION - Copy] column for values, using "Don't Aggregate".

vjingzhanmsft_1-1716432235992.png

4. Sort table by DESCRIPCION column ascendingly. 

5. Reorder columns. 

 

Full code:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUXIEYkMDpVidaCUjINMJxDUFc42BTGcgNoLIghS7gGSN4IpdQVwTuGI3qN5YAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [NIVEL = _t, DESCRIPCION = _t, CANTIDAD = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"NIVEL", Int64.Type}, {"DESCRIPCION", type text}, {"CANTIDAD", Int64.Type}}),
    #"Duplicated Column" = Table.DuplicateColumn(#"Changed Type", "NIVEL", "NIVEL - Copy"),
    #"Duplicated Column1" = Table.DuplicateColumn(#"Duplicated Column", "DESCRIPCION", "DESCRIPCION - Copy"),
    #"Added Prefix" = Table.TransformColumns(#"Duplicated Column1", {{"NIVEL - Copy", each "NIVEL" & Text.From(_, "en-US"), type text}}),
    #"Pivoted Column" = Table.Pivot(#"Added Prefix", List.Distinct(#"Added Prefix"[#"NIVEL - Copy"]), "NIVEL - Copy", "DESCRIPCION - Copy"),
    #"Sorted Rows" = Table.Sort(#"Pivoted Column",{{"DESCRIPCION", Order.Ascending}}),
    #"Reordered Columns" = Table.ReorderColumns(#"Sorted Rows",{"NIVEL", "DESCRIPCION", "NIVEL1", "NIVEL2", "NIVEL3", "CANTIDAD"})
in
    #"Reordered Columns"

vjingzhanmsft_0-1716432026952.png

 

Best Regards,
Jing
If this post helps, please Accept it as Solution to help other members find it. Appreciate your Kudos!

View solution in original post

2 REPLIES 2
MARRASARG1974
Frequent Visitor

Muchas gracias por tu respuesta! Funciono perfecto!

v-jingzhan-msft
Community Support
Community Support

Hi @MARRASARG1974 

 

Here is my solution. Steps:

1. Duplicate NIVEL column and DESCRIPCION column.

2. Add prefix string "NIVEL" to [NIVEL - Copy] column. 

3. Pivot [NIVEL - Copy] column and select [DESCRIPCION - Copy] column for values, using "Don't Aggregate".

vjingzhanmsft_1-1716432235992.png

4. Sort table by DESCRIPCION column ascendingly. 

5. Reorder columns. 

 

Full code:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUXIEYkMDpVidaCUjINMJxDUFc42BTGcgNoLIghS7gGSN4IpdQVwTuGI3qN5YAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [NIVEL = _t, DESCRIPCION = _t, CANTIDAD = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"NIVEL", Int64.Type}, {"DESCRIPCION", type text}, {"CANTIDAD", Int64.Type}}),
    #"Duplicated Column" = Table.DuplicateColumn(#"Changed Type", "NIVEL", "NIVEL - Copy"),
    #"Duplicated Column1" = Table.DuplicateColumn(#"Duplicated Column", "DESCRIPCION", "DESCRIPCION - Copy"),
    #"Added Prefix" = Table.TransformColumns(#"Duplicated Column1", {{"NIVEL - Copy", each "NIVEL" & Text.From(_, "en-US"), type text}}),
    #"Pivoted Column" = Table.Pivot(#"Added Prefix", List.Distinct(#"Added Prefix"[#"NIVEL - Copy"]), "NIVEL - Copy", "DESCRIPCION - Copy"),
    #"Sorted Rows" = Table.Sort(#"Pivoted Column",{{"DESCRIPCION", Order.Ascending}}),
    #"Reordered Columns" = Table.ReorderColumns(#"Sorted Rows",{"NIVEL", "DESCRIPCION", "NIVEL1", "NIVEL2", "NIVEL3", "CANTIDAD"})
in
    #"Reordered Columns"

vjingzhanmsft_0-1716432026952.png

 

Best Regards,
Jing
If this post helps, please Accept it as Solution to help other members find it. Appreciate your Kudos!

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.

Top Solution Authors