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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

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
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.