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

Get sum of contract amount by month bases on start and end date

Hi Guys,

 

I have some struggels to get the correct results. Hope you can help me out.

There are some contracts for monthly fee. These have a start date, an end date and an amount. I would like to know per month what the total revenue/fee is. When the end date is empty, the contract is open and delivers each month a fee.

 

 

I have set up 1 new date tabel which shows each month and create some dax with some comparision with the date, the start date and the end date, but I cannot get the right results.

 

Revenue =
CALCULATE(
SUM('Contracts'[Amount €]),
FILTER(
ALLSELECTED('Contracts'),
('Revenue'[Date2] >= MIN('Contracts'[Start date]) &&
'Revenue'[Date2] <= MIN('Contracts'[end date]) && NOT(ISBLANK('Contracts'[End Date]))) ||
('Revenue'[Date2] >= MIN('Contracts'[Start Date]) &&
ISBLANK('Contracts'[End Date]))
))
 
data:
ContractCompanyStart dateend dateamount €
C-001A1-8-20211-2-2022100
C-002A1-2-2022 150
C-003B1-9-20211-11-2021110
C-004B1-11-20211-1-2022115
C-004B1-1-20221-4-2022120

 

Expecting result:

1-8-2021100
1-9-2021210
1-10-2021210
1-11-2021215
1-12-2021215
1-1-2022220
1-2-2022270

 

pbix file attached: https://1drv.ms/u/s!Akhij5oHG_75nJQw6GNWiLlg1Nv-9A?e=x98k0I

Thanks a lot. Please let me know if you need more info!

1 ACCEPTED SOLUTION

Try

Revenue Column = 
var currentDate = 'Revenue'[Date2]
return CALCULATE( SUM(Contracts[amount €]),Contracts[Start date] <=  currentDate && ( ISBLANK( 'Contracts'[end date]) || 'Contracts'[end date] > currentDate ) ) 

View solution in original post

6 REPLIES 6
Anonymous
Not applicable

Hi johnt75,

 

Thanks for your reply, but this isn't working for me. I would like to have a colum in a table with this information because I want to append this table with another table which has similar data.

You could create a column on the Revenue table by deleting the MIN() and MAX() from my code so that it is just using the Date column from the current row.

Anonymous
Not applicable

Tried that, but DAX isn't excepting the code because it cannot find the [Date2] column. It is only finding this column when using MAX MIN and that kind of functions. Or am I doing something wrong?

 

Revenue Measure = CALCULATE( SUM(Contracts[amount €]),Contracts[Start date] <=  'Revenue'[Date2] && ( ISBLANK( 'Contracts'[end date]) || 'Contracts'[end date] > 'Revenue'[Date2] ) ) 

 

 

 

Try

Revenue Column = 
var currentDate = 'Revenue'[Date2]
return CALCULATE( SUM(Contracts[amount €]),Contracts[Start date] <=  currentDate && ( ISBLANK( 'Contracts'[end date]) || 'Contracts'[end date] > currentDate ) ) 
Anonymous
Not applicable

I should have known that trick with the variable by now...

You are the men! Thank you very much for your help and your patient!

johnt75
Super User
Super User

you can create a new measure

Revenue Measure = CALCULATE( SUM(Contracts[amount €]),Contracts[Start date] <= MIN( 'Revenue'[Date2]) &&
    ( ISBLANK( 'Contracts'[end date]) || 'Contracts'[end date] > MAX('Revenue'[Date2] ) )
)

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.