Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!
Hola
Por el momento, tengo datos que se ven así:
Título del proyecto | Fecha de inicio de inicio | Fecha de finalización del inicio | Fecha de inicio del diseño | Fecha de finalización del diseño |
Proyecto 1 | 2020-01-01 | 2020-05-01 | 2020-07-01 | 2020-12-01 |
Proyecto 2 | 2022-01-01 | 2022-03-01 | 2022-08-01 | 2023-01-01 |
Proyecto 3 | 2021-02-01 | 2021-06-01 | 2021-10-01 | 2022-03-01 |
Quiero tener solo una columna de fecha de inicio y fecha de finalización y crear una nueva columna que identifique la fase. ¿Alguien sabe cómo hacer esta transformación?
Título del proyecto | Fase | Fecha de inicio | Fecha final |
Proyecto 1 | Iniciación | 2020-01-01 | 2020-05-01 |
Proyecto 1 | Diseño | 2020-07-01 | 2020-12-01 |
Proyecto 2 | Iniciación | 2022-01-01 | 2022-03-01 |
Proyecto 2 | Diseño | 2022-08-01 | 2023-01-01 |
Proyecto 3 | Iniciación | 2021-02-01 | 2021-06-01 |
Proyecto 3 | Diseño | 2021-10-01 | 2022-03-01 |
@POMduff ,
Puedes hacerlo. Por favor, siga los pasos a continuación,
Paso 1 : Duplique la tabla de origen y elimine las columnas "Fecha de inicio de inicio", "Fecha de finalización de inicio" de la tabla duplicada. Su tabla duplicada debería verse como la siguiente después de eliminar las columnas mencionadas anteriormente.
Paso 2: Elimine la "Fecha de inicio de diseño", "Fecha de finalización del diseño" de la tabla de origen y luego agregue la tabla duplicada a la tabla de origen. Debería verse como el siguiente,
y luego pegue el código de consulta de Power adjunto en el código del editor avanzado, obtendrá el resultado.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCijKz0pNLlEwVNJRMjIwMtA1MAQiOMcUmWOOxDE0AnFidRAmGEGkjJBNAHKMkTkWcI4xVBmyCcYQKaC4EVwdkGOGxDE0wDA7NhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Project Title" = _t, #"Initiation Start Date" = _t, #"Initiation End Date" = _t, #"Design Start Date" = _t, #"Design End Date" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Project Title", type text}, {"Initiation Start Date", type date}, {"Initiation End Date", type date}, {"Design Start Date", type date}, {"Design End Date", type date}}),
#"Removed Columns1" = Table.RemoveColumns(#"Changed Type",{"Design Start Date", "Design End Date"}),
#"Appended Query" = Table.Combine({#"Removed Columns1", #"Duplicate of Sample Table to append"}),
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Appended Query", {"Project Title"}, "Attribute", "Value"),
#"Added Conditional Column" = Table.AddColumn(#"Unpivoted Other Columns", "Start Date", each if [Attribute] = "Initiation Start Date" then [Value] else if [Attribute] = "Design Start Date" then [Value] else null),
#"Added Conditional Column1" = Table.AddColumn(#"Added Conditional Column", "End Date", each if [Attribute] = "Initiation End Date" then [Value] else if [Attribute] = "Design End Date" then [Value] else null),
#"Removed Columns" = Table.RemoveColumns(#"Added Conditional Column1",{"Value"}),
#"Filled Up" = Table.FillUp(#"Removed Columns",{"End Date"}),
#"Removed Alternate Rows" = Table.AlternateRows(#"Filled Up",1,1,1),
#"Renamed Columns" = Table.RenameColumns(#"Removed Alternate Rows",{{"Attribute", "Phase"}}),
#"Replaced Value" = Table.ReplaceValue(#"Renamed Columns","Start Date","",Replacer.ReplaceText,{"Phase"}),
#"Sorted Rows" = Table.Sort(#"Replaced Value",{{"Project Title", Order.Ascending}})
in
#"Sorted Rows"
Gracias