Forum Discussion

pbi_taken's avatar
pbi_taken
Icon for Helper I rankHelper I
2 years ago
Solved

Distribute budget evenly between startdate and finishdate

I have a table that looks like the one below.  I have been given the task to find a way to evenly distribute the budget between startdate and enddate in a visual. Probably something like a barchart ...
  • danextian's avatar
    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