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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Syndicate_Admin
Administrator
Administrator

Despivota

Hola a todos

Tengo 35 preguntas para las que tengo un resultado, las mismas preguntas se implementaron el año pasado, también tengo resultados de eso, tengo que comparar y mostrar los resultados a la gerencia, traté de despivotar ambos conjuntos de preguntas cuando lo puse en las métricas, los resultados muestran incorrectos, por favor, ayude a resolver este problema. Debajo de la hoja de Google para el conjunto de datos

https://docs.google.com/spreadsheets/d/1KVclPSCHdvxHyHkIBxfiUMFDhOqxg2kb2fOgu5qioWA/edit?usp=sharing

1. De la columna E a la AM son los resultados de este año

2. Resultado del año pasado de AN a BW

5 REPLIES 5
Syndicate_Admin
Administrator
Administrator

Hi AlexisOlson,

Gracias por el código, lamento decir que no podré usar esta función ya que hay pocas otras columnas, como departamentos y subdepartamentos, que deben asignarse y son más de miles, así que ¿puede sugerir alguna otra opción?

Es difícil sugerir algo sin datos de muestra que reflejen cuál es su situación real.

¿Cuál es la parte de mi ejemplo que no funciona para ti? ¿Enumerar los nombres de las columnas?

El código es muy similar.

let
    Source = Excel.Workbook(File.Contents("C:\Users\aolson\Downloads\Sample raw_data.xlsx"), null, true),
    Sheet1_Sheet = Source{[Item="Sheet1",Kind="Sheet"]}[Data],
    #"Promoted Headers" = Table.PromoteHeaders(Sheet1_Sheet, [PromoteAllScalars=true]),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Promoted Headers", {"Sl no", "Gender", "State", "Zone", "Department"}, "Question", "Value"),
    #"Added Custom" = Table.AddColumn(#"Unpivoted Other Columns", "Year", each if Text.Contains([Question], "_") then "Last Year" else "This Year", type text),
    #"Extracted Text Before Delimiter" = Table.TransformColumns(#"Added Custom", {{"Question", each Text.BeforeDelimiter(_, "_"), type text}}),
    #"Pivoted Column" = Table.Pivot(#"Extracted Text Before Delimiter", List.Distinct(#"Extracted Text Before Delimiter"[Year]), "Year", "Value"),
    #"Changed Type1" = Table.TransformColumnTypes(#"Pivoted Column",{{"This Year", Int64.Type}, {"Last Year", type number}, {"Sl no", Int64.Type}, {"Gender", type text}, {"State", type text}, {"Zone", type text}, {"Department", type text}, {"Question", type text}})
in
    #"Changed Type1"

Ver archivo adjunto.

Syndicate_Admin
Administrator
Administrator

¿Es este el tipo de transformación que estás buscando?


A partir de esto:

AlexisOlson_0-1704318519686.png

A esto:

AlexisOlson_1-1704318552858.png

Código de ejemplo para lo anterior:

let
  Source = Table.FromRows(
    {
      {1, "Male", "North", "Active", 1, 2, 3, 4, 2, 4, 6, 8}, 
      {2, "Female", "Central", "Active", 3, 5, 7, 9, 2, 4, 6, 8}, 
      {3, "Male", "South", "Inactive", 0, 2, 4, 6, 0, 4, 8, 12}
    }, 
    type table [
      ID = number, Gender = text, Zone = text, Status = text, 
      a = number, b = number, c = number, d = number, 
      A = number, B = number, C = number, D = number
    ]
  ),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"ID", "Gender", "Zone", "Status"}, "Column", "Value"),
    #"Added Custom" = Table.AddColumn(#"Unpivoted Other Columns", "Year", each if List.Contains({"a","b","c","d"}, [Column]) then "This Year" else if List.Contains({"A","B","C","D"}, [Column]) then "Last Year" else null, type text),
    #"Uppercased Text" = Table.TransformColumns(#"Added Custom",{{"Column", Text.Upper, type text}}),
    #"Pivoted Column" = Table.Pivot(#"Uppercased Text", List.Distinct(#"Uppercased Text"[Year]), "Year", "Value")
in
  #"Pivoted Column"

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Top Solution Authors
Top Kudoed Authors