Forum Discussion
Distribute budget evenly between startdate and finishdate
- 2 years ago
Hi pbi_taken
This would be a simple feat with Power Query and I prefer this method. Please you need to count how many months are within the range if you need the granularity to be by month then you generate rows with months/dates within the range. This is a sample M Code
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("XY9LCgQxCAXv4roZ/MZ4ltD3v8ZEkwEZyKZ4FX2uBQQPIH32Y6TZgGWDKxHB+yzgjPh60YBxg05HKy9/ofR5F1jTi9DjJaHeKBpINvLhePZaRtbnWSuhoczljYzGnWcHCH/gImOU5xn59fgfQiyivFo1+94LfPoJn35VPboX7V6i6TLhfb8=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [id = _t, startdate = _t, enddate = _t, budget = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"id", Int64.Type}, {"startdate", type date}, {"enddate", type date}, {"budget", Int64.Type}}), #"Added Custom" = Table.AddColumn(#"Changed Type", "Count of Months", each Number.Round(Number.From(([enddate] - [startdate])/( 365.25 / 12 )) ,0 )), #"Added Custom1" = Table.AddColumn(#"Added Custom", "Split", each {0..[Count of Months]}), #"Expanded Split" = Table.ExpandListColumn(#"Added Custom1", "Split"), #"Added Custom2" = Table.AddColumn(#"Expanded Split", "Dates", each Date.AddMonths([startdate],[Split])), #"Added Custom3" = Table.AddColumn(#"Added Custom2", "Distributed Budget", each [budget]/( [Count of Months] + 1) ), #"Removed Columns" = Table.RemoveColumns(#"Added Custom3",{"Count of Months", "Split"}), #"Changed Type1" = Table.TransformColumnTypes(#"Removed Columns",{{"Dates", type date}, {"Distributed Budget", type number}}) in #"Changed Type1"The total of distributed budget should be equal to the total of the actual budget per id
Hi pbi_taken ,
There is no need to create a relationship between the two tables. Just put the id field in the legend. Also, you can put startdate and enddate in tooltip if you want to know their exact dates.
More detailed information can be found in the attachment.
If your Current Period does not refer to this, please clarify in a follow-up reply.
Best Regards,
Clara Gong
If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Thanks! but i still see issues with this as it shows me the same amount for all years. It should se how many months is in the start year and end year and evenly distribute by number of months in the year..