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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
TE
Helper I
Helper I

Sum of values between two dates in same column

 

I have two tables: one that contains payments and another that contains the start date of a contract. These two tables are linked by a dates table and a table containing unique company names. 

 

I would like to calculate the sum of payments for each company on or after the start date of a contract and before the next start date of the companies new contract. Heres a excel representation of my tables. 


Capture excel.PNG

 

 

 

Thanks in advance!

 

-TE

1 ACCEPTED SOLUTION
v-juanli-msft
Community Support
Community Support

Hi @TE

Look at my test

First, manage relationships among these tables

1.png

Second, in "company"table, create calculated columns

min = LOOKUPVALUE(Sheet1[min],Sheet1[company],[company])

max = LOOKUPVALUE(Sheet1[max],Sheet1[company],[company])

2.png

 

Third, in Sheet2,create calculated columns

min = RELATED(company[min])

max = RELATED(company[max])

flag = IF([max]=[min],1,0)

max2 = IF([flag]=1,CALCULATE(MAX([payment date]),ALLEXCEPT(Sheet2,Sheet2[company]))+1,[max])

sum = CALCULATE(SUM(Sheet2[payment]),FILTER(ALLEXCEPT(Sheet2,Sheet2[company]),[payment date]>=[min]&&[payment date]<[max2]))

3.png

 

 

Best Regards

Maggie

View solution in original post

1 REPLY 1
v-juanli-msft
Community Support
Community Support

Hi @TE

Look at my test

First, manage relationships among these tables

1.png

Second, in "company"table, create calculated columns

min = LOOKUPVALUE(Sheet1[min],Sheet1[company],[company])

max = LOOKUPVALUE(Sheet1[max],Sheet1[company],[company])

2.png

 

Third, in Sheet2,create calculated columns

min = RELATED(company[min])

max = RELATED(company[max])

flag = IF([max]=[min],1,0)

max2 = IF([flag]=1,CALCULATE(MAX([payment date]),ALLEXCEPT(Sheet2,Sheet2[company]))+1,[max])

sum = CALCULATE(SUM(Sheet2[payment]),FILTER(ALLEXCEPT(Sheet2,Sheet2[company]),[payment date]>=[min]&&[payment date]<[max2]))

3.png

 

 

Best Regards

Maggie

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors