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.
Hola
Tengo 4 columnas en una tabla correspondiente al salario de 2018, el salario de 2019 hasta 202 dependiendo de diferentes personas.
También tengo una tabla que contiene fechas de 2018 a 2021.
Me gustaría crear un mesure que sumará y mostrará el salario dependiendo de las fechas de mi columna.
Como si la fecha es 2021, sumo las columnas salario de 2021, si la fecha es 2018, hago lo mismo pero con la columna 2018
Por lo tanto, me gustaría que alguien pensara así
Muchas gracias
Ten un buen día
Solved! Go to Solution.
Aquí tienes:
Pasos a seguir en alto nivel:
Código M como se muestra a continuación:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("dU9BDsAgCPsLZw846j5D/P83hsPEdM4DaRtKU9ylSpGqqgFXwkcNGmMxkF78VXMJsuJ0MZjl0loCqf0CwchJYve31Rv0xbHTveJA4fjt1B8=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, #"Salary 2018" = _t, #"Salary 2019" = _t, #"Salary 2020" = _t, #"Salary 2021" = _t, #"Income 2018" = _t, #"Income 2019" = _t, #"Income 2020" = _t, #"Income 2021" = _t]),
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"ID"}, "Attribute", "Value"),
#"Split Column by Delimiter" = Table.SplitColumn(#"Unpivoted Other Columns", "Attribute", Splitter.SplitTextByDelimiter(" ", QuoteStyle.Csv), {"Attribute", "Year"}),
#"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Value", Int64.Type}}),
#"Pivoted Column" = Table.Pivot(#"Changed Type1", List.Distinct(#"Changed Type1"[Attribute]), "Attribute", "Value")
in
#"Pivoted Column"
La tabla se ve así:
Y simplemente visualízalo en forma de tabla:
Espero que esto funcione para ti.
Por favor, proporcione un elogio a esta respuesta si la encontró interesante.
Si esta publicación ayuda, considere aceptarla como la solución para ayudar a otros miembros a encontrarla más rápidamente.
Tenga una DateTable con la que pueda crear una relación con su tabla principal.
Cree una medida llamada suma de salario como esta
Suma salarial = Suma(MainTable[Salario]) y luego visualícelo en su informe contra Año de DatesTable como se muestra a continuación:
Hola
Gracias por su respuesta, pero tengo 4 columnas de salario, así que no puedo sumarlas, creo, por ejemplo, tengo
y me gustaría usar mi segunda tabla donde tengo fechas para poder tener esto:
Donde las columnas de la derecha son la suma del salario correspondiente al año
De acuerdo.. Ahora eso hace que el problema sea mucho más claro.
Necesitas despivotar las columnas aquí.
Vaya a Power Query y vaya al Editor avanzado y pegue este código allí después de eliminar el código existente:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("VY7BDcAwCAN34Z0HCU6XQey/RklRCryswwajSpMGTWZ2WSGVbCittNCCuAlxkJjJDil0EnBoToHj7+xF++LveHIX7dJHZi8=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, #"Salary 2018" = _t, #"Salary 2019" = _t, #"Salary 2020" = _t, #"Salary 2021" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Salary 2018", Int64.Type}, {"Salary 2019", Int64.Type}, {"Salary 2020", Int64.Type}, {"Salary 2021", Int64.Type}}),
#"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"ID"}, "Attribute", "Value"),
#"Split Column by Delimiter" = Table.SplitColumn(#"Unpivoted Columns", "Attribute", Splitter.SplitTextByDelimiter(" ", QuoteStyle.Csv), {"Attribute.1", "Attribute.2"}),
#"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Attribute.1", type text}, {"Attribute.2", Int64.Type}}),
#"Removed Columns" = Table.RemoveColumns(#"Changed Type1",{"Attribute.1"}),
#"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Attribute.2", "Year"}, {"Value", "Salary"}})
in
#"Renamed Columns"
La tabla se vería así:
Ahora puede visualizarlo en forma de tabla como se muestra a continuación:
¡Muchas gracias!
y en caso de que tenga esto:
y quiero tener esto:
¿Qué debo cambiar en el código para tener este resultado?
Lo intenté pero no lo logré
¡Gracias!
Aquí tienes:
Pasos a seguir en alto nivel:
Código M como se muestra a continuación:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("dU9BDsAgCPsLZw846j5D/P83hsPEdM4DaRtKU9ylSpGqqgFXwkcNGmMxkF78VXMJsuJ0MZjl0loCqf0CwchJYve31Rv0xbHTveJA4fjt1B8=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, #"Salary 2018" = _t, #"Salary 2019" = _t, #"Salary 2020" = _t, #"Salary 2021" = _t, #"Income 2018" = _t, #"Income 2019" = _t, #"Income 2020" = _t, #"Income 2021" = _t]),
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"ID"}, "Attribute", "Value"),
#"Split Column by Delimiter" = Table.SplitColumn(#"Unpivoted Other Columns", "Attribute", Splitter.SplitTextByDelimiter(" ", QuoteStyle.Csv), {"Attribute", "Year"}),
#"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Value", Int64.Type}}),
#"Pivoted Column" = Table.Pivot(#"Changed Type1", List.Distinct(#"Changed Type1"[Attribute]), "Attribute", "Value")
in
#"Pivoted Column"
La tabla se ve así:
Y simplemente visualízalo en forma de tabla:
Espero que esto funcione para ti.
Por favor, proporcione un elogio a esta respuesta si la encontró interesante.
Si esta publicación ayuda, considere aceptarla como la solución para ayudar a otros miembros a encontrarla más rápidamente.
Gracias que es perfecto
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
2 | |
1 | |
1 | |
1 | |
1 |
User | Count |
---|---|
2 | |
2 | |
2 | |
1 | |
1 |