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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Ctwzl
New Member

List all months between two dates of a contract in a seperate table

I really need your help because I am stuck for quite some time now to generate the revenue by month of contracts. I have a contracts table with a start and end date and I want to calculate the revenue per month. I have tried many solutions and used ChatGPT but I keep failing to get the desired output. I think the main reason is that many solutions will list all the days between the start and end date. Then create a calculated table with crossjoin and that's too much data (my assumption) because it loads until I get an error message that something went wrong.

 

In order to fix this I guess I only need the months between the dates to limit the data. If a contract runs from the 1st of January to 31st of March I only want three rows and not 90 rows for all days (February should always be 28 days).


My contracts table looks like this:

Contract IDIsDuplicateStart DateEnd DateAnnual Value
A101-01-202431-03-20241200
A001-01-202431-03-20241200
B112-04-202412-06-20242400

 

It's worth mentioning here that my contracts table has duplicates that I want to remove by selecting IsDuplicate = 1 to avoid double revenue due to those contract lines.

My expected output of a calculatedtable would be:

Contract IDYear-MonthDaysInMonthContractDays in MonthAnnual Value
A2024-0131311200
A2024-0228281200
A2024-0331311200
B2024-0430182400
B2024-0531312400
B2024-0630122400


I would really appreciate some help here to get this working. If you think there is a better method for this than please let me know.

2 ACCEPTED SOLUTIONS

ThxAlot_0-1730235104138.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LearnAndPractise(Everyday)


)



View solution in original post

4 REPLIES 4
lbendlin
Super User
Super User

This is a standard amortization pattern. but you will need to define what to do with partial months like your contract B.

 

 

 

(February should always be 28 days)

 

 

Nopedy-nope.  This year it was 29.  But it wouldn't really matter if you amortize monthly with each month getting 1/12th of the yearly value.  Which takes us right back to your contract B.  

 

lbendlin_0-1730212758279.png

For 2024 you can multiply the annual value by the contract days and divide by 366. For other years use 365 etc.  This will become fun when contracts extend across years.

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTIEYgNDXSAyMjAyAXKMgRxjGMfQyMBAKVYHotSAOKVOUFMNjXQNTBCyugZmMI6RCUhpLAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Contract ID" = _t, IsDuplicate = _t, #"Start Date" = _t, #"End Date" = _t, #"Annual Value" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"IsDuplicate", Int64.Type}, {"Annual Value", Currency.Type}, {"Start Date", type date}, {"End Date", type date}},"nl"),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type", each ([IsDuplicate] = 1)),
    #"Added Custom" = Table.AddColumn(#"Filtered Rows", "Date", each List.Dates([Start Date],Number.From([End Date]-[Start Date])+1,#duration(1,0,0,0))),
    #"Expanded Date" = Table.ExpandListColumn(#"Added Custom", "Date"),
    #"Added Custom1" = Table.AddColumn(#"Expanded Date", "Year-Month", each Date.ToText([Date],[Format = "yyyy-MM"]),type text),
    #"Grouped Rows" = Table.Group(#"Added Custom1", {"Contract ID", "Year-Month"}, {{"Contract Days in Month", each Table.RowCount(_), Int64.Type}, {"Annual Value", each List.Max([Annual Value]), type nullable number}})
in
    #"Grouped Rows"

 

How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done". Once you examined the code, replace the entire Source step with your own source.

 

I know that this year February had 29 days. However for some reason the annual value (this data comes from a different report) is always calcualted based on 365 days no matter the year. Because I want to make sure the revenue by month matches I need use 28 days for February. Otherwise I will always slightly off for everything in 2024.

ThxAlot_0-1730235104138.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LearnAndPractise(Everyday)


)



Sigh...

lbendlin_1-1730213393409.png

 

 

lbendlin_0-1730213372294.png

 

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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