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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Calculate Prior Last 12 Months Revenue DAX formula

Hi,
I have a requirement to display Prior Last 12 Months Revenue which computes the rolling sum of the Sales Amount measure over the prior last 12 months.

SaloniGupta_0-1622609012915.png
SaloniGupta_1-1622609181894.png

 e.g for 12th November 2020, the sum of the sales amount between the dates 12th November 2018 and 12th November 2019

To compute Prior Last 12 Months Revenue, I have tried the below shown DAX formula:

 

Prior Last 12 Months Revenue =
VAR StartPeriod = DATEADD('Transaction Date'[Date],-1,YEAR)
Return
CALCULATE (
SUM('Transaction'[Sales Amount]),
DATESBETWEEN (
'Transaction Date'[Date],
NEXTDAY ( SAMEPERIODLASTYEAR ( LASTDATE(StartPeriod ) ) ),
LASTDATE ( StartPeriod )
)
)

 

The result is as shown below (when analyzed for 1 Client):

SaloniGupta_1-1622610386461.png

 

The result is coming correctly for 2019 as it is showing Sales Amount values for 2018 i.e. Prior Year. But it also displays 2018 aggregated amounts for 2017 and 2020 Transaction Dates as well which should be left blank ideally.

Please suggest correct DAX to calculate Prior Year Last 12 Months Revenue.
Thanks in advance!

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous , with help from date table.

 

Example

Rolling 12 = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date ],MAX('Date'[Date ]),-12,MONTH))

 

Last 12 before 12 = CALCULATE(SUM(Sales[Net Sales]), DATESINPERIOD('Date'[Date], maxx('Date', DATEADD('Date'[Date],-12,MONTH)),-12, MONTH))

 

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@Anonymous , with help from date table.

 

Example

Rolling 12 = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date ],MAX('Date'[Date ]),-12,MONTH))

 

Last 12 before 12 = CALCULATE(SUM(Sales[Net Sales]), DATESINPERIOD('Date'[Date], maxx('Date', DATEADD('Date'[Date],-12,MONTH)),-12, MONTH))

 

Anonymous
Not applicable

Thanks, @amitchandak It worked 👍😊

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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