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
vidyasagar159
Helper II
Helper II

Trailing 3 months are showing wrong values when removing empty records from another column

Hi All,

 

I have a product table with prices and dates for year 2017 along with the modified date (Starts from 3rd Quarter) and modified amount. Now my requirement is to create trailing 3 months and subtract the trailing 3 months - modified amount. This was easy when it is in the actual table. But when I am trying to show the data only for the modified date is not blank my trailing 3 Month calculations were going wrong. Not sure where it is going wrong. Can someone please help.

 

Here is the 3 Months trailing measure expression.

 

Trailing3months =
var currentdate = MAX(Main[Monthly Price])
var previousdate = DATE(YEAR(currentdate),MONTH(currentdate)-3,DAY(currentdate))
Var Result =
CALCULATE (
SUM(Main[Price]),
FILTER(ALLSELECTED(Main),Main[Monthly Price]>previousdate && Main[Monthly Price] <= currentdate)
)
return
Result

 

Sample Data:

Main Table
Product Monthly Price PriceTrailing 3 MonthModified dateModified AmountTrailing 3 Month - Modified Amount
Apple05/01/2017$200    
Apple06/01/2017$210    
Apple07/01/2017$196$606   
Apple08/01/2017$150$55608/01/2017$50$506
Apple09/01/2017$170$51609/01/2017$30$486
Apple10/01/2017$160$48010/01/2017$40$440
Apple11/01/2017$180$51011/01/2017$20$490
Apple12/01/2017$200$54012/01/2017$10$530
       
       
Expected output Table
Product Monthly Price PriceTrailing 3 MonthModified dateModified AmountTrailing 3 Month - Modified Amount
Apple08/01/2017$150$55608/01/2017$50$506
Apple09/01/2017$170$51609/01/2017$30$486
Apple10/01/2017$160$48010/01/2017$40$440
Apple11/01/2017$180$51011/01/2017$20$490
Apple12/01/2017$200$54012/01/2017$10$530

 

Thanks,

-Vidya

1 ACCEPTED SOLUTION
Ashish_Mathur
Super User
Super User

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


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

View solution in original post

4 REPLIES 4
Ashish_Mathur
Super User
Super User

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


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

@Ashish_Mathur Thank you so much. 

 

-Vidya

You are welcome.


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

Try using datesinperiod

Make sure you have calendar date table for that

 

Rolling 3 = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date Filer],ENDOFMONTH(Sales[Sales Date]),-3,MONTH))  

 

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution. In case it does not help, please provide additional information and mark me with @
Thanks.

My Recent Blog - https://community.powerbi.com/t5/Community-Blog/Comparing-Data-Across-Date-Ranges/ba-p/823601

 

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.