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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

AverageX and Excel Disagree

Interesting situation here.

 

Using averageX to claculate the last X months returns values that differ from the same calculations in Excel.

beenherebefore_0-1720200417341.png

The dark blue line is the number being averaged.

The Light blue line is the resultant average.

The first result (last number in the visual...13.11), is dead on with the Excel result:

beenherebefore_6-1720201501949.png

 

But the numbers diverge from that point on:

beenherebefore_5-1720201158734.png

 

The number that is being averaged (M_ComplaintsPer1MEA) is the result of a series of measures.

 

Please Wax Poetic

 

Update: All columns and measures inolved are defined as decimal with 4 decimal places.

 

 

 

 

 

 

 

1 ACCEPTED SOLUTION
OwenAuger
Super User
Super User

Hiya @Anonymous 

While the June 2024 12-month average looks correct, the earlier averages look to be 11 month averages. Not sure whether the issue is measure definition or something else in the model.

 

Here is how I would write the Avg of previous 12 measure myself. This assumes you have a 'Date' table set up in the usual way with a "Year Month" or equivalent column:

 

 

Avg of previous 12 = 
CALCULATE (
    AVERAGEX (
        VALUES ( 'Date'[Year Month] ),
        [M_CompIaintsPerIMEA]
    ),
    DATESINPERIOD ( 'Date'[Date], MAX ( 'Date'[Date] ), -12, MONTH )
)

 

Note: When fewer than 12 months are available, this measure will average the available months (can be modified to return blank instead).

 

OwenAuger_0-1720252111642.png

Are you able to get something like this working?

 

PBIX attached.

 

Regards


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

View solution in original post

3 REPLIES 3
OwenAuger
Super User
Super User

Hiya @Anonymous 

While the June 2024 12-month average looks correct, the earlier averages look to be 11 month averages. Not sure whether the issue is measure definition or something else in the model.

 

Here is how I would write the Avg of previous 12 measure myself. This assumes you have a 'Date' table set up in the usual way with a "Year Month" or equivalent column:

 

 

Avg of previous 12 = 
CALCULATE (
    AVERAGEX (
        VALUES ( 'Date'[Year Month] ),
        [M_CompIaintsPerIMEA]
    ),
    DATESINPERIOD ( 'Date'[Date], MAX ( 'Date'[Date] ), -12, MONTH )
)

 

Note: When fewer than 12 months are available, this measure will average the available months (can be modified to return blank instead).

 

OwenAuger_0-1720252111642.png

Are you able to get something like this working?

 

PBIX attached.

 

Regards


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn
Anonymous
Not applicable

I tried your Dax and still eneded up with the same numbers. But when I read where you mention it appareaed to be the average of he last 11 instead of 12, I decided to change the -12 in my Dax to -13 and shazam!

 

Either my spreadsheet was doing a 13 month or Bi counts funny.

 

M_CasesRolling12MosEA =
VAR ReferenceDate = MAX('calendar'[date])
VAR PreviousDates =
    DATESINPERIOD(
    'presentation_calandar'[Date],
    ReferenceDate,
    -13,
    MONTH
    )
VAR Result =
    CALCULATE(
    AVERAGEX(
        DATESINPERIOD(
            'calendar'[Month & Year],
            LASTDATE('calendar'[Month & Year]),
            -13,
            MONTH
        ),
        [M_ComplaintsPer1MEAMonth]
    ),
        ALL('calendar'),
        KEEPFILTERS(PreviousDates),
        USERELATIONSHIP('calendar'[date],'presentation_calandar'[Date])
        )
   
RETURN
Result

This worked for me as well! Thanks for sharing this.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.