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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

distribution of a budget in remaining Months

Hi everyone, 

I have a budget and would like to distribut it in remaiming month of the year. for ex;

Budget =1000 for a year 

actual till end of March = 700

remaining = 1000-700=300

remaining month to end of year = 3 month 

so each month has = 100 (April =100, May=100 and Jun 100) 

my formula is like below

column called divider 

= Table.AddColumn(#"Removed Columns", "Divider", each if Date.Month(DateTime.LocalNow()) = 1 then 5 else if Date.Month(DateTime.LocalNow()) = 2 then 4 else if Date.Month(DateTime.LocalNow()) = 3 then 3 else if Date.Month(DateTime.LocalNow()) = 4 then 2 else if Date.Month(DateTime.LocalNow()) = 5 then 1 else if Date.Month(DateTime.LocalNow()) = 6 then 1 else if Date.Month(DateTime.LocalNow()) = 7 then 11 else if Date.Month(DateTime.LocalNow()) = 8 then 10 else if Date.Month(DateTime.LocalNow()) = 9 then 9 else if Date.Month(DateTime.LocalNow()) = 10 then 8 else if Date.Month(DateTime.LocalNow()) = 11 then 7 else if Date.Month(DateTime.LocalNow()) = 12 then 6 else null)

second column for April

Table.AddColumn(#"Added Custom9", "Apr", each if Date.Month(DateTime.LocalNow())=4 then 0 else if Date.Month(DateTime.LocalNow())<4 then 0 else [Cost To Complete]/[Divider])

* Cost To Complete = Total Budget - Actual budget. 

my problem is, the formula doesn't show the correct answer? does anyone has a btter idea to distibute the remaining budget in remaining month ? 

Thanks for every one 

 

1 ACCEPTED SOLUTION
camargos88
Community Champion
Community Champion

Hi @Anonymous ,

 

Try this m code:

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQwMFDSUTIw1Dcw1jcyMAJxzIFCsTrRSqZwKXOYlBFIKhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Budget = _t, Date = _t, Consumed = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Budget", Int64.Type}, {"Date", type date}, {"Consumed", Int64.Type}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each let _startDate = [Date],
_nMonths = if Date.Month([Date]) <= 6 then
6 - Date.Month([Date])
else
(12 - Date.Month([Date])) + 6,
_endDate = Date.AddMonths(_startDate, _nMonths + 1)
in
List.Select(List.Dates(_startDate, Duration.Days(_endDate - _startDate), #duration(1,0,0,0)), each Date.StartOfMonth(_) = _)),
#"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "Custom"),
#"Changed Type1" = Table.TransformColumnTypes(#"Expanded Custom",{{"Custom", type date}}),
#"Added Custom1" = Table.AddColumn(#"Changed Type1", "Custom.1", each if [Date] = [Custom] then [Consumed]
else
let _date = [Date] in
([Budget] - [Consumed]) / (Table.RowCount(Table.SelectRows(#"Expanded Custom", each [Date] = _date)) - 1)),
#"Renamed Columns" = Table.RenameColumns(#"Added Custom1",{{"Custom", "NewDate"}, {"Custom.1", "NewConsumed"}}),
#"Changed Type2" = Table.TransformColumnTypes(#"Renamed Columns",{{"NewConsumed", type number}})
in
#"Changed Type2"

 

Capture.PNG

 

 



Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



View solution in original post

1 REPLY 1
camargos88
Community Champion
Community Champion

Hi @Anonymous ,

 

Try this m code:

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQwMFDSUTIw1Dcw1jcyMAJxzIFCsTrRSqZwKXOYlBFIKhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Budget = _t, Date = _t, Consumed = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Budget", Int64.Type}, {"Date", type date}, {"Consumed", Int64.Type}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each let _startDate = [Date],
_nMonths = if Date.Month([Date]) <= 6 then
6 - Date.Month([Date])
else
(12 - Date.Month([Date])) + 6,
_endDate = Date.AddMonths(_startDate, _nMonths + 1)
in
List.Select(List.Dates(_startDate, Duration.Days(_endDate - _startDate), #duration(1,0,0,0)), each Date.StartOfMonth(_) = _)),
#"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "Custom"),
#"Changed Type1" = Table.TransformColumnTypes(#"Expanded Custom",{{"Custom", type date}}),
#"Added Custom1" = Table.AddColumn(#"Changed Type1", "Custom.1", each if [Date] = [Custom] then [Consumed]
else
let _date = [Date] in
([Budget] - [Consumed]) / (Table.RowCount(Table.SelectRows(#"Expanded Custom", each [Date] = _date)) - 1)),
#"Renamed Columns" = Table.RenameColumns(#"Added Custom1",{{"Custom", "NewDate"}, {"Custom.1", "NewConsumed"}}),
#"Changed Type2" = Table.TransformColumnTypes(#"Renamed Columns",{{"NewConsumed", type number}})
in
#"Changed Type2"

 

Capture.PNG

 

 



Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.

Top Solution Authors