Forum Discussion
Help with lookback measure
I am trying to write a new measure that will go back 12 months, from date, and avg the next 6 months from that 12 month look back.
So the general idea is go back 12 months then avg -12 mths thru -6 mths from given month yr. I do have a date table, but the chart is using Month Year, instead of day.
| month yr | Sales | Look-back |
| Jan 2017 | 1000 | |
| Feb 2017 | 1001 | |
| Mar 2017 | 2002 | |
| Apr 2017 | 3003 | |
| May 2017 | 1004 | |
| Jun 2017 | 1005 | |
| Jul 2017 | 1007 | |
| Aug 2017 | 2008 | |
| Sep 2017 | 312 | |
| Oct 2017 | 3134 | |
| Nov 2017 | 3138 | |
| Dec 2017 | 6285 | |
| Jan 2018 | 7521 | |
| Feb 2018 | 1546 | Avg Sales (Feb 2017 thru Aug 2017) |
| Mar 2018 | 2549 | Avg Sales (Mar 2017 thru Sep 2017) |
| Apr 2018 | 55674 | Avg Sales (Apr 2017 thru Oct 2017) |
| May 2018 | 3232 | AVG Sales (May 2017 thru Nov 2017) |
| Jun 2018 | 6464 | Avg Sales (Jun 2017 thru Dec 2017) |
4 Replies
- amitchandak
Super User
I think you are looking for 6 before 6. make sure you have date table.
Rolling 12 = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],ENDOFMONTH(Sales[Sales Date]),-12,MONTH)) Rolling 12 = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],max(Sales[Sales Date]),-12,MONTH)) Rolling last 6 before 6 = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],ENDOFMONTH(dateadd('Date'[Date],-6,MONTH)),-6,MONTH))To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/ - v-lid-msft
Community Support
Hi cwnoll ,
We can try to use the following measure to meet your requirement:
Look-back = VAR d = MAX ( 'Calendar'[Date] ) RETURN CALCULATE ( SUM ( 'Sales'[Amount] ), FILTER ( ALLSELECTED ( 'Calendar' ), 'Calendar'[Date] >= DATE ( YEAR ( d ) - 1, MONTH ( d ), 1 ) && 'Calendar'[Date] < DATE ( YEAR ( d ) - 1, MONTH ( d ) + 7, 1 ) ) ) / 6If it does not meet your requirement, could you please describle the fields of each tables and the relations between tables simply? Please don't have any Confidential Information or Real data in your reply.
Best regards, - Ashish_Mathur
Super User
Hi,
Share the link from where i can download your PBI file.
- v-lid-msft
Community Support
Hi cwnoll ,
How about the result after you follow the suggestions mentioned in my original post?Could you please provide more details about it If it doesn't meet your requirement?
Best regards,