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
Christina_C
Helper I
Helper I

Last 12 Mo. Average $ Sales Measure to Include Months with Zero Dollars

Below is a matrix of sales for the last 13 months.  I am looking to calculate the last 12 month average. Within my measure "Avg $ Sales/ 12 Mo", it is not including the months with zero dollars in sales.  The result I am looking for should be 236, not 707. 

 

Can anyone help me update this measure?  Please and thank you 🙂 

 

Christina_C_0-1667494596246.png

 
Average Last 12 Mo. =
VAR NumOfMonths = 12
VAR LastSelectedDate = MAX ( 'Calendar'[Date] )
VAR Period =
    DATESINPERIOD ( 'Calendar'[Date], LastSelectedDate, -NumOfMonths, MONTH )
VAR Result =
    CALCULATE (
        AVERAGEX (
            VALUES ( 'Calendar'[Month Number] ),
            [Total Sales]
        ),
        Period
    )
VAR LastDateWithSale = MAX ( 'VALUE ENTRY'[Posting Date] )
VAR FirstVisibleDate = MIN ('Calendar'[Date])
RETURN
    IF( FirstVisibleDate <= LastDateWithSale, Result )

 

 

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Christina_C , if you want inculde month with no sales

 

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

 

 

Do not inculde month with 0 sales

 

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

View solution in original post

2 REPLIES 2
Christina_C
Helper I
Helper I

@amitchandak It worked!! Thank you so much!!

amitchandak
Super User
Super User

@Christina_C , if you want inculde month with no sales

 

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

 

 

Do not inculde month with 0 sales

 

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

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.