Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

Remaining Budget Calculation (Days)

Hi Everyone,    I have a table where I have the follwoing details:  Project Name Project Start Date Project End Date Budget (In $) P1 1/1/2023 4/30/2023 10000 P2 1/1/2023 5/30/202...
  • adudani's avatar
    3 years ago

    Hi Anonymous ,

     

    create a blank query and paste the following code:

    let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCijKz0pNLlHwS8xNVdKBc4NLEotKFFwSS5AFXfNSYEJOpSnpqSUKGp55CiqaSrE6QIMMgcKG+ob6RgZGxkCmib6xAYxtaAAEEFVGqKpMkVSZIlQZo6oyQ1JlhlBlgqrK0EgfiJCtBKqLBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"(blank)" = _t, #"(blank).1" = _t, #"(blank).2" = _t, #"(blank).3" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"(blank)", type text}, {"(blank).1", type text}, {"(blank).2", type text}, {"(blank).3", type text}}),
    #"Promoted Headers" = Table.PromoteHeaders(#"Changed Type", [PromoteAllScalars=true]),
    #"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{"Project Name", type text}, {"Project Start Date", type date}, {"Project End Date", type date}, {"Budget (In $)", type number}}),
    ProjectDuration = Table.AddColumn(#"Changed Type1", "ProjectDuration", each Duration.Days([Project End Date] - [Project Start Date])+1, Int64.Type),
    DailyBudget = Table.AddColumn(ProjectDuration, "DailyBudget", each [#"Budget (In $)"]/[ProjectDuration]),
    #"Changed Type2" = Table.TransformColumnTypes(DailyBudget,{{"DailyBudget", type number}}),
    Custom1 = Table.AddColumn(#"Changed Type2", "#DaysinProjectCompleted", each Duration.Days(Date.From(DateTime.FixedLocalNow()) - [Project Start Date])+1, Int64.Type),
    #"Amount Billed Including today" = Table.AddColumn(Custom1, "Amount Billed Including today", each [DailyBudget]*[#"#DaysinProjectCompleted"]),
    #"Changed Type3" = Table.TransformColumnTypes(#"Amount Billed Including today",{{"Amount Billed Including today", type number}}),
    BudgetLeft = Table.AddColumn(#"Changed Type3", "BudgetLeft", each [#"Budget (In $)"]-[Amount Billed Including today]),
    #"Changed Type4" = Table.TransformColumnTypes(BudgetLeft,{{"BudgetLeft", type number}})
    in
    #"Changed Type4"

     

     

    This is the final output.

     

     

     

    The intermediate steps can be reduced if this meets the requirement.

     

    Appreciate a thumbs up if this helps.

     

    Please accept this as the solution if the question is resolved.