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

Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers. Get Fabric certified for FREE! Learn more

Reply
Anonymous
Not applicable

Sum of Dates between Transaction Date - 1 Year & Transaction Date

I am trying to get a measure that is the sum of sales between the Date of the Transaction for a row and the last year (365 days).

 

I tried:

Trailing12Months = (CALCULATE(sum(PS_SalesHistory[Project Funding]), DATESINPERIOD(PS_SalesHistory[Month].[Date], LASTDATE(PS_SalesHistory[Month].[Date]), -1, YEAR)))
 
But this is only giving me the dates between the current date and the prior 365.
 
I tried creating a new table, but I'm getting an error there too:
Trailing12Months = ADDCOLUMNS(PS_SalesHistory, "Trailing12Months", DATESINPERIOD(PS_SalesHistory[Month].[Date], LASTDATE(PS_SalesHistory[Month].[Date]), -1, YEAR))
 
1 ACCEPTED SOLUTION
v-xiaotang
Community Support
Community Support

Hi @Anonymous 

you can use the function DATESINPERIOD() & EDATE(), and it will the period you need, for example,

vxiaotang_1-1623920313214.png

so you can do sum calculation for last 12 months by creating the measure bellow, e.g.

 

Trailing12Months = 
var _currentdate=EDATE(MIN(PS_SalesHistory[Month]),-1) 
return 
CALCULATE(sum(PS_SalesHistory[Project Funding]), DATESINPERIOD(PS_SalesHistory[Month],_currentdate,-1,YEAR))

 

 

 

Best Regards,

Community Support Team _ Tang

If this post helps, please consider Accept it as the solution✔️ to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
v-xiaotang
Community Support
Community Support

Hi @Anonymous 

you can use the function DATESINPERIOD() & EDATE(), and it will the period you need, for example,

vxiaotang_1-1623920313214.png

so you can do sum calculation for last 12 months by creating the measure bellow, e.g.

 

Trailing12Months = 
var _currentdate=EDATE(MIN(PS_SalesHistory[Month]),-1) 
return 
CALCULATE(sum(PS_SalesHistory[Project Funding]), DATESINPERIOD(PS_SalesHistory[Month],_currentdate,-1,YEAR))

 

 

 

Best Regards,

Community Support Team _ Tang

If this post helps, please consider Accept it as the solution✔️ to help the other members find it more quickly.

Anonymous
Not applicable

Moving this back to the top of the list to see if anyone knows how to solve it

Anonymous
Not applicable

@amitchandak       

I tried both your formulas and its not giving me what I'm looking for.

 

Last Year Sales is giving me the total for each Fiscal Year.

 

Year Behind Sales is giving me the total for the Calendar Year.

 

I need the sum of the sales for the last 12 months for each row.

 

For example:

 

Basic Data:

1/1/2020 3
2/1/2020 4
3/1/2020 5
4/1/2020 6
5/1/2020 7
6/1/2020 8
7/1/2020 1
8/1/2020 2
9/1/2020 3
10/1/2020 4
11/1/2020 5
12/1/2020 6
1/1/2021 7
2/1/2021 8
3/1/2021 9
4/1/2021 10
5/1/2021 12

 

This would give us:

1/1/2021 51
2/1/2021 54
3/1/2021 57
4/1/2021 60
5/1/2021 63

 

Basically the calculation for 1/1/2021 is the last 12 months added togethor:

1/1/2020 3

2/1/2020 4
3/1/2020 5
4/1/2020 6
5/1/2020 7
6/1/2020 8
7/1/2020 1
8/1/2020 2
9/1/2020 3
10/1/2020 4
11/1/2020 5
12/1/2020 6

 

And the calculation for 2/1/2021 is the prior 12 months would sum 2/1/2020 to 1/1/2021

3/1/2021 would sum 3/1/2020 to 2/1/2021

 

Let me  know if you have any questions

amitchandak
Super User
Super User

@Anonymous , if you need last year , not rolling 365 days

rolling your formula should work

 

Last year Sales = CALCULATE(sum(PS_SalesHistory[Project Funding]),DATESYTD(ENDOFYEAR(dateadd('Date'[Date],-1,Year)),"12/31"))

 

Year behind Sales = CALCULATE(sum(PS_SalesHistory[Project Funding]),previousyear('Date'[Date]))

 

use date table

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :radacad sqlbi My Video Series Appreciate your Kudos.

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
PBIApril_Carousel

Power BI Monthly Update - April 2025

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

Notebook Gallery Carousel1

NEW! Community Notebooks Gallery

Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.

April2025 Carousel

Fabric Community Update - April 2025

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

Top Solution Authors