cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
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
v-yuta-msft
Community Support
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))

1.PNG2.PNG

 

Regards,

Jimmy Tao

View solution in original post

8 REPLIES 8
v-yuta-msft
Community Support
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))

1.PNG2.PNG

 

Regards,

Jimmy Tao

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 Smiley Happy

afzalphatan
Resolver I
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

afzalphatan
Resolver I
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... 

Chris99
Advocate III
Advocate III

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

Helpful resources

Announcements
August 1 episode 9_no_dates 768x460.jpg

The Power BI Community Show

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

Power BI Dev Camp Session 24 without aka link and time 768x460.jpg

Ted's Dev Camp - July 28, 2022

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

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Top Solution Authors
Top Kudoed Authors