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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

How to calculate with only data from the last year

Dear community, 

 

I'm currently struggling with the following problem. I've got a salestable with amounts and invoicedates. I've also got another table that always contains one date which I transferred into a date table. Now I want to calculate the total amount but only for the period of a year previous to the date in the date table. I tried it as follows: 

 

Total cost revenue LTM = CALCULATE(SUMX(CUSTINVOICETRANS;[Total costprice revenue]);DATESINPERIOD('Date'[Date];MAX('Date'[Date]);-1;YEAR))
 
But I got zero output. Could anyone assist? Many thanks in advance!
 
Gr. Diana
1 ACCEPTED SOLUTION
Greg_Deckler
Community Champion
Community Champion

@Anonymous Maybe:

Measure = 
  VAR __Date = MAX('Dates'[Date])
  VAR __StartDate = DATE(YEAR(__Date)-1,MONTH(__Date),DAY(__Date))
  VAR __Table = FILTER('CUSTINVOICETRANS',[InvoiceDate]>=__StartDate && <=__Date)
RETURN
  SUMX(__Table,[Total costprice revenue])

You may find this helpful - https://community.powerbi.com/t5/Community-Blog/To-bleep-With-Time-Intelligence/ba-p/1260000

Also, see if my Time Intelligence the Hard Way provides a different way of accomplishing what you are going for.

https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TITHW/m-p/434008



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

2 REPLIES 2
Greg_Deckler
Community Champion
Community Champion

@Anonymous Maybe:

Measure = 
  VAR __Date = MAX('Dates'[Date])
  VAR __StartDate = DATE(YEAR(__Date)-1,MONTH(__Date),DAY(__Date))
  VAR __Table = FILTER('CUSTINVOICETRANS',[InvoiceDate]>=__StartDate && <=__Date)
RETURN
  SUMX(__Table,[Total costprice revenue])

You may find this helpful - https://community.powerbi.com/t5/Community-Blog/To-bleep-With-Time-Intelligence/ba-p/1260000

Also, see if my Time Intelligence the Hard Way provides a different way of accomplishing what you are going for.

https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TITHW/m-p/434008



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Dear Greg, 

 

Thank you for you response. I had to adjust it a little bit but that was probably due to the fact that by datetable is a little bit strange because it only contains one value, but the output is now correct! 

 

Total cost revenue LTM =
VAR _Date = MAX('Date'[Date])
VAR _Startdate = DATE(YEAR(_Date)-1;MONTH(_Date);DAY(_Date))
VAR _Table = FILTER(CUSTINVOICETRANS;CUSTINVOICETRANS[INVOICEDATE]>=_Startdate)
Return
SUMX(_Table;[Total costprice revenue])

 

 

With kind regards, 

 

Diana

 

 

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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!

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.