cancel
Showing results for
Did you mean:
Anonymous
Not applicable

## Average from today back six months

Hi All,

I need to do something that is probably super simple but i cant seem to work out how.

I have a table that has a column in that represents the level of satisfaction with a service we deliver

The management team only want me to report satisfaction for the last six months from the current date.

so far i've got this

6MONTH = CALCULATE(AVERAGEX(MSF,MSF[Satisfaction]),
DATESINPERIOD(MSF[Date],LASTDATE(MSF[Date]),-6,MONTH))

but it calculates the average over all of the data and doesnt filter for 6 months. I have a date table in the model should I use that and change the measure to days rather than months.

1 ACCEPTED SOLUTION
Community Support

Hi cxputcm,

Based on your description, you want to filter the last 6 months in a visual, right?

You can modify you measure like this:

`6MONTH = CALCULATE(AVERAGEX(MSF,MSF[Satisfaction]),  DATESINPERIOD(MSF[Date], TODAY(),-6,MONTH))`

Regards,

Jimmy Tao

8 REPLIES 8
Community Support

Hi cxputcm,

Based on your description, you want to filter the last 6 months in a visual, right?

You can modify you measure like this:

`6MONTH = CALCULATE(AVERAGEX(MSF,MSF[Satisfaction]),  DATESINPERIOD(MSF[Date], TODAY(),-6,MONTH))`

Regards,

Jimmy Tao

Frequent Visitor

Does this works even if you don't have the today's date in the table?

Out of interest am I missing something? Why is everyone suggesting going down the DAX route when the visual has a filter that can be used?

Chris

Anonymous
Not applicable

Hi Chris,

Just wanted to confirm the filter method also works but I was looking to build an independant measure that would display dynamically

Thanks for your help all, its much appreciated

@Anonymous No problem

Resolver I

DATESINPERIOD  and all other time functions in DAX works well only with "continuous dates in dimension table".......

You can create a seperate dimDate table staring with 1st Jan and ends with 31st dec .... make a realationship and use DATESINPERIOD( DimDate, LASTDATE(MSF[Date]),-6,MONTH )

HOPES THIS SOLVES UR Prob

Resolver I

Can  you share Pic of sample data (small and similar to ur situation) and the expected result in the column side to it...

Hi @Anonymous

In the Filters section of your table select the date field. In the filter properties select a Filter Type of "Relative date filtering". Then choose "is in the last" and set the value to 6. Change the drop down below it from "days" to "months" or "calendar months" depending on your exact requirement. Click on Apply filter and that should hopefully do the job.

Chris

Announcements

#### The Power BI Community Show

Watch the playback when Priya Sathy and Charles Webb discuss Datamarts! Kelly also shares Power BI Community updates.

#### Ted's Dev Camp - July 28, 2022

Watch Session 24 of Ted's Dev Camp along with past sessions!