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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
pbi_taken
Helper I
Helper I

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 that will show the budget per year and month by project.

Does anyone know how to solve this?

 

idstartdateenddatebudget
101.01.201801.01.202374111
202.01.201902.01.202048705
303.01.201803.01.202449945
404.01.202904.01.203176701
505.01.201805.01.201949422
606.01.202506.10.202573366
707.01.202207.01.202293599
808.01.201808.01.202176321
909.01.201809.01.2024118738

 

 

Thank you so much!

1 ACCEPTED SOLUTION
danextian
Super User
Super User

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"

 

danextian_0-1725970799105.png

 

The total of distributed budget should be equal to the total of the actual budget per id

danextian_1-1725970854582.png

 

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

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


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

View solution in original post

5 REPLIES 5
danextian
Super User
Super User

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"

 

danextian_0-1725970799105.png

 

The total of distributed budget should be equal to the total of the actual budget per id

danextian_1-1725970854582.png

 

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

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


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
Sahir_Maharaj
Super User
Super User

Hello @pbi_taken,

 

Can you please try this approach:

 

1. Create a Date Table

DateTable = 
ADDCOLUMNS(
    CALENDAR(MIN(Table[startdate]), MAX(Table[enddate])),
    "Year", YEAR([Date]),
    "MonthNumber", MONTH([Date]),
    "YearMonth", YEAR([Date]) * 100 + MONTH([Date]),
    "MonthName", FORMAT([Date], "MMM")
)

2. Calculate the Number of Months Between Start and End Date

MonthsBetween = 
DATEDIFF(Table[startdate], Table[enddate], MONTH) + 1

3. Calculate the Monthly Budget

MonthlyBudget = 
DIVIDE(Table[budget], Table[MonthsBetween])

4. Sum the Monthly Budget

DistributedBudget = 
VAR StartDate = MIN(Table[startdate])
VAR EndDate = MAX(Table[enddate])
VAR MonthlyBudget = DIVIDE(SUM(Table[budget]), DATEDIFF(StartDate, EndDate, MONTH) + 1)
RETURN
CALCULATE(
    MonthlyBudget,
    FILTER(
        DateTable,
        DateTable[Date] >= StartDate &&
        DateTable[Date] <= EndDate
    )
)

Hope this helps.


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,
Sahir Maharaj
Data Scientist | Data Engineer | Data Analyst | AI Engineer
P.S. Want me to build your Power BI solution? (Yes, its FREE!)
➤ Lets connect on LinkedIn: Join my network of 15K+ professionals
➤ Join my free newsletter: Data Driven: From 0 to 100
➤ Website: https://sahirmaharaj.com
➤ About: https://sahirmaharaj.com/about.html
➤ Email: sahir@sahirmaharaj.com
➤ Want me to build your Power BI solution? Lets chat about how I can assist!
➤ Join my Medium community of 30K readers! Sharing my knowledge about data science and artificial intelligence
➤ Explore my latest project (350K+ views): Wordlit.net
➤ 100+ FREE Power BI Themes: Download Now
LinkedIn Top Voice in Artificial Intelligence, Data Science and Machine Learning

This looks promosing, but what should the relation between datetable and table be? 
If its between startdate and datetable it filters for just the startdate and if it's no relationship every year is in my graph and start and enddate does not matter.. like the image below, when actually startdate is in january 2018 and enddate is in january 2024...

pbi_taken_0-1725973622422.png

 

Anonymous
Not applicable

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.

vkaiyuemsft_0-1726036589310.png

 

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..

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors