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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
DLU
Helper I
Helper I

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
Super User
Super User

@DLU 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-TIT...


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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

2 REPLIES 2
Greg_Deckler
Super User
Super User

@DLU 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-TIT...


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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.