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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Anonymous
Not applicable

DAX - DATESADD FUNCTION (MTD AVerage of Previous Month)

Hi, I need help in this really bad.

I am trying to obtain Current MTD Average & Previous MTD Average of selected dates through a filter.

I have used the Following measure for the current MTD average:

Avg_DAILYBASE_CM =
CALCULATE(
    AVERAGE('DB'[DAILY_ACTIVE])
    , DATESMTD('DB'[DATA_DATE]
    ))
and used the Following measure for previous MTD average:
Avg_DAILYBASE_LM =
CALCULATE(
    AVERAGE('DB'[DAILY_ACTIVE]),
    DATEADD('DB'[DATA_DATE], -1, MONTH)
)
The data is calculated accurately (as attached in picture), but the total average is incorrect for the previous month's MTD. Can anyone please help out in this? Would really appreciate123.png

5 REPLIES 5
tamerj1
Super User
Super User

Hi @Anonymous 

please try

Avg_DAILYBASE_LM =
AVERAGEX (
VALUES ( 'DB'[DATA_DATE] ),
CALCULATE (
AVERAGE ( 'DB'[DAILY_ACTIVE] ),
DATEADD ( 'DB'[DATA_DATE], -1, MONTH )
)
)

Anonymous
Not applicable

@Mahesh0016 Hi thankyou for your reply, but unfortunately the issue still presists. after doing the recommended change the averages in days values have further become incorrect.

Plus the total average of the selected date range is of CM.

Hashmi_0-1686390023769.png

 

@Anonymous Please Try this

@Anonymous I hope this helps you!!THANK YOU!!
Avg_DAILYBASE_LM =
var MX_Month = MAX('DB'[DATA_DATE])-1
RETURN

CALCULATE(
    AVERAGE('DB'[DAILY_ACTIVE]),
    DATESINPERIOD('DB'[DATA_DATE], MX_Month,-1, MONTH)
)
Mahesh0016
Super User
Super User

@Anonymous I hope this helps you!!THANK YOU!!
var MX_Month = MAX('DB'[DATA_DATE])-1

Avg_DAILYBASE_LM =
CALCULATE(
    AVERAGE('DB'[DAILY_ACTIVE]),
    DATESINPERIOD('DB'[DATA_DATE], MX_Month,-1, MONTH)
)

@Anonymous Please share your ENDOUTPUT in table for better understanding.

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.

Top Solution Authors