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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Syndicate_Admin
Administrator
Administrator

Crear tabla basada en 2 fechas seguidas

Quiero crear una tabla basada en 2 fechas en una línea. Para que quede más claro, hice un ejemplo.

Tabla de origen

ObjetoEstadoFecha de inicioFecha de finalización Presupuesto RO pm
Coche XActivo1-3-2023corriente € 500,00
Porque YNo activo1-5-202131-8-2021 € 300,00
Coche ZActivo16-5-2023corriente € 400,00

Tabla de destino

ObjetoFechaPresupuesto pm
Coche X31-3-2023 € 500,00
Coche X30-4-2023 € 500,00
Coche X31-5-2023 € 500,00
Coche X30-6-2023 € 500,00
Porque Y31-5-2023 € 300,00
Porque Y30-6-2023 € 300,00
Porque Y31-7-2021 € 300,00
Porque Y31-8-2021 € 300,00
Coche Z31-5-2023 € 206,45 (400*16/31)
Coche Z30-6-2023 € 400,00

¿Hay alguien que pueda ayudarme a :)?

¡Atentamente!

2 REPLIES 2
Syndicate_Admin
Administrator
Administrator

¡Perfecto! Gracias 🙂

Syndicate_Admin
Administrator
Administrator

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".

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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