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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
adarshalok
Frequent Visitor

Remaining Budget Calculation (Days)

Hi Everyone, 

 

I have a table where I have the follwoing details: 

Project NameProject Start DateProject End DateBudget (In $)
P11/1/20234/30/202310000
P21/1/20235/30/202350000
P31/1/20236/30/202360000
P41/1/202312/12/2023100000

 

I would like to show how much of my budget are remaining as of the current date (Budget gets split into number of days until project ends and as the date progresses, the budget remaining should show the available budget (Excluding the $ amount which has already been billed into the project).

 

Eg: P3 is for 6months aka frm 1/1/23 to 6/30/23 and has a budget of $60000.  As of 1/1/23, the remaining budget is $60,000. As of 3/30/23. the remaining budget now is ~$30,000. 

 

Any help would be appreciated. 

 

1 ACCEPTED SOLUTION
adudani
Super User
Super User

Hi @adarshalok ,

 

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.

 

adudani_0-1672957909191.png

 

 

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.

Did I answer your question? Mark my post as a solution, this will help others!
If my response(s) assisted you in any way, don't forget to drop me a Kudos 🙂
Kind Regards,
Avinash

View solution in original post

1 REPLY 1
adudani
Super User
Super User

Hi @adarshalok ,

 

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.

 

adudani_0-1672957909191.png

 

 

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.

Did I answer your question? Mark my post as a solution, this will help others!
If my response(s) assisted you in any way, don't forget to drop me a Kudos 🙂
Kind Regards,
Avinash

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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