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! Learn more

Reply
jordi012
Advocate II
Advocate II

Calculate YTD between dates of the same table

Hi,

 

I am having a little trouble caculating the YTD amounts between 2 dates of the same table. Looks like Power BI Modeler, only accepts 1 relationship to the Time_Dim (Calendar table). Any Ideas how to write that in DAX?? this is the code I have tried so far without success...Help will be immensely appreciated.

 

YTDBetween2Dates= Calculate (
 sum (QuotesAnualTest[Amount]) ;
  FILTER ( QuotesAnualTest ;
    COUNTROWS ( FILTER( VALUES(' Time_Dim'[DateId]) ;
      QuotesAnualTest[StartDateId] <= Time_Dim[DateId] &&
      QuotesAnualTest[EndDateId] >= Time_Dim[DateId] ))
    > 0)
  )

2 REPLIES 2
v-haibl-msft
Microsoft Employee
Microsoft Employee

@jordi012

 

I’m not very clear about your requirement. Could you please give some sample data and the expected output result?

 

Best Regards,

Herbert

Of course I can. I think I can explain myself a little beter... 🙂 We have the following Data regarding contracts. Every contract has a date when it was signed and some of them where signed off or cancelled, and a Fee.

 

I have a Contracts_Fact table that include the Date of Opening and the Date of Closing the contract, linked with the Time_Dim in Power BI.

 

Expected: I need a bar chart showing the value of the fees every year taking into account that some contracts have expired and do not need to be summed up any longer. Actually is not a YTD, it's rather showing the amount of fees every year of the valid contracts that I have. For example, in the table given, the contract number 1, should show 30 euros each month of 2015, until the 30th of January 2016, after that point in time its value should be 0 (because the contracts is closed)

I give you an example of the data that I expect to plot on the bar chart:

 

Month               Value of Contracts

January 15:           30+20

February 15:          30+20

...

February 16:        20+10 (contract 1 was closed)

...etc

 

On the table, the bank values on the column mean that the contract has not been closed.

 

ContractIdAnual FeeDateOpeningDateClosing
1301/1/201530/01/2016
2202/1/2015 
3103/1/201617/01/2017
4151/4/2014 
5201/5/201625/07/2016
64001/02/2015 

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