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
sjpusat16
New Member

3 month average with year change

Hi, I am working on a measure to calculate the average of the previous 3 months' sales. I figured this out for months that are all in the same year, then I realized that in January the measure wouldn't work. Currently I calculate 3 measures for Month-1, Month-2, and Month-3, and then add them up and divide by 3 to get the average. Here is what Month-2 looks like (the other 2 measures are the exact same just different offsets of the month):

Month-2 = CALCULATE(SUM(Query3[Amt]), RollingCalendar[Month] = MONTH(TODAY())-2, RollingCalendar[Year] = YEAR(MAX(RollingCalendar[Date])))
 
Obviously when the 3 month interval crosses over a new year, this will create an issue. Can someone point me in the right direction on how to cover this exception?
1 ACCEPTED SOLUTION
rubayatyasmin
Super User
Super User

Hi, @sjpusat16 

 

use EDATE dax func. 

 

for example, 

 

RollingCalendar[Month] = MONTH(EDATE(TODAY(), -2)),

RollingCalendar[Year] = YEAR(EDATE(TODAY(), -2))

 

refer to this doc: https://learn.microsoft.com/en-us/dax/edate-function-dax

 

rubayatyasmin_0-1689517080227.png


Did I answer your question? Mark my post as a solution!super-user-logo

Proud to be a Super User!


View solution in original post

1 REPLY 1
rubayatyasmin
Super User
Super User

Hi, @sjpusat16 

 

use EDATE dax func. 

 

for example, 

 

RollingCalendar[Month] = MONTH(EDATE(TODAY(), -2)),

RollingCalendar[Year] = YEAR(EDATE(TODAY(), -2))

 

refer to this doc: https://learn.microsoft.com/en-us/dax/edate-function-dax

 

rubayatyasmin_0-1689517080227.png


Did I answer your question? Mark my post as a solution!super-user-logo

Proud to be a Super User!


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.