Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.
Quiero crear una tabla basada en 2 fechas en una línea. Para que quede más claro, hice un ejemplo.
Tabla de origen
Objeto | Estado | Fecha de inicio | Fecha de finalización | Presupuesto RO pm |
Coche X | Activo | 1-3-2023 | corriente | € 500,00 |
Porque Y | No activo | 1-5-2021 | 31-8-2021 | € 300,00 |
Coche Z | Activo | 16-5-2023 | corriente | € 400,00 |
Tabla de destino
Objeto | Fecha | Presupuesto pm |
Coche X | 31-3-2023 | € 500,00 |
Coche X | 30-4-2023 | € 500,00 |
Coche X | 31-5-2023 | € 500,00 |
Coche X | 30-6-2023 | € 500,00 |
Porque Y | 31-5-2023 | € 300,00 |
Porque Y | 30-6-2023 | € 300,00 |
Porque Y | 31-7-2021 | € 300,00 |
Porque Y | 31-8-2021 | € 300,00 |
Coche Z | 31-5-2023 | € 206,45 (400*16/31) |
Coche Z | 30-6-2023 | € 400,00 |
¿Hay alguien que pueda ayudarme a :)?
¡Atentamente!
¡Perfecto! Gracias 🙂
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wck4sUohQ0lFyTC7JLEsFMgx1jXWNDIyMgcyi0ry8zLx0IEvhUdMaBWRgamCgY2CgFKsDMSESqMYvv0QByRRTkCmGQKaxoa4FjI1hjjGqOVEoLjGDGELAKSZQI2IB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Object = _t, Status = _t, Startdate = _t, Enddate = _t, #" Budget RO pm " = _t]),
#"Replaced Value" = Table.ReplaceValue(Source,"running",null,Replacer.ReplaceValue,{"Enddate"}),
#"Changed Type" = Table.TransformColumnTypes(#"Replaced Value",{{"Startdate", type date}, {"Enddate", type date}, {" Budget RO pm ", Currency.Type}},"nl"),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Months", (k)=> List.Generate(()=>k[Startdate],each _ < (k[Enddate] ?? Date.From(DateTime.LocalNow())), each Date.AddMonths(_,1),each Date.StartOfMonth(_))),
#"Expanded Months" = Table.ExpandListColumn(#"Added Custom", "Months"),
#"Changed Type1" = Table.TransformColumnTypes(#"Expanded Months",{{"Months", type date}}),
#"Added Custom1" = Table.AddColumn(#"Changed Type1", "Budget pm", each if Date.Year([Startdate]) = Date.Year([Months])
and Date.Month([Startdate]) = Date.Month([Months])
and Date.Day([Startdate])<> Date.Day([Months])
then Duration.Days(Date.AddMonths([Months],1)-[Startdate])/Duration.Days(Date.AddMonths([Months],1)-[Months])*[#" Budget RO pm "]
else [#" Budget RO pm "],Currency.Type)
in
#"Added Custom1"
Cómo usar este código: Crear una nueva consulta en blanco. Haga clic en "Editor avanzado". Reemplace el código en la ventana con el código proporcionado aquí. Haga clic en "Listo".