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 September 15. Request your voucher.

Reply
afwork
Frequent Visitor

Calculate sum of and between dates

Hello,

Can you please help me with this?

I want a measure that calculates the sum of Apples between 01/01/2024 to 29/02/2024 (end date dynamic based on slicer selected).

 

I started with this but it doesn't work.

 

Thank you

 

Apple YTD =
CALCULATE(SUM(PL_Transactions[AccountingAmt]), PL_Transactions[Type] = "Apple", DATESBETWEEN(PL_Transactions[AccountDate],DATE(SELECTEDVALUE(PL_Transactions[AccountDate].[Year]),1,1),EOMONTH(DATE(SELECTEDVALUE(PL_Transactions[AccountDate].[Year]),SELECTEDVALUE(PL_Transactions[AccountDate].[MonthNo]),1),0)))

 

 

TypeAccountingAmtAccountDate
Orange639031/01/2024
Apple6897628/01/2024
Orange79742315/01/2024
Apple24336822/01/2024
Apple30446829/01/2024
Apple6746035/02/2024
Orange38134412/02/2024
Orange30328219/02/2024
Orange82933326/02/2024
Apple729454/03/2024
Orange31786411/03/2024
   
Answer1912201 
1 ACCEPTED SOLUTION
Ritaf1983
Super User
Super User

Hi @afwork 
As a first step create a dim date table, it will help you with this issue anf for future analyses :

Ritaf1983_0-1729316578832.png

more information about dim date tables and why you should use them here :

https://blog.coupler.io/power-bi-calendar-table/

2. create a relationship with your main table by date

Ritaf1983_1-1729316726529.png

3. create a measure :

apples sum =
var start_ = date(2024,01,01)
var end_ = max('DimDate'[Date])
RETURN
CALCULATE(SUM('Table'[AccountingAmt]),ALL(DimDate[Date]),'Table'[Type]="apple",DATESBETWEEN('DimDate'[Date],start_,end_))
Result :
Ritaf1983_2-1729316785465.png

The pbix is attached

If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

View solution in original post

8 REPLIES 8
Ritaf1983
Super User
Super User

Hi @afwork 
As a first step create a dim date table, it will help you with this issue anf for future analyses :

Ritaf1983_0-1729316578832.png

more information about dim date tables and why you should use them here :

https://blog.coupler.io/power-bi-calendar-table/

2. create a relationship with your main table by date

Ritaf1983_1-1729316726529.png

3. create a measure :

apples sum =
var start_ = date(2024,01,01)
var end_ = max('DimDate'[Date])
RETURN
CALCULATE(SUM('Table'[AccountingAmt]),ALL(DimDate[Date]),'Table'[Type]="apple",DATESBETWEEN('DimDate'[Date],start_,end_))
Result :
Ritaf1983_2-1729316785465.png

The pbix is attached

If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

How to make this prior year please:

var end_ = max('DimDate'[Date])

Hi @afwork 
var end_ = max('DimDate'[Date])-365

If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

Thank you! This worked as intended.

Happy to help💗

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile
Ashish_Mathur
Super User
Super User

Hi,

PBI file attached.

Hope this helps.

Ashish_Mathur_0-1729314739343.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

I don't want a slicer for Apple, only for date please.

Thank you!

File attached.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

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.