Forum Discussion
Forecast 2 weeks trend
Hi All,
I have below data in my file, I need to write a DAX which can forcast the coverage value for next 2 weeks as per the existing last 8 weeks actual data, could someone help me with the DAX.
| Date | Coverage |
| 7/18/2023 | 43314.28 |
| 7/19/2023 | 46587.21 |
| 7/21/2023 | 50430.32 |
| 7/24/2023 | 57365.00 |
| 7/25/2023 | 64887.25 |
| 7/26/2023 | 68135.19 |
| 7/27/2023 | 70492.60 |
| 7/28/2023 | 72082.89 |
| 7/31/2023 | 75085.72 |
| 8/2/2023 | 84301.20 |
| 8/7/2023 | 96150.63 |
| 8/8/2023 | 18234.13 |
| 8/9/2023 | 21217.45 |
| 8/10/2023 | 27157.69 |
| 8/11/2023 | 36911.57 |
| 8/14/2023 | 41654.31 |
| 8/15/2023 | 49327.01 |
| 8/16/2023 | 50051.84 |
| 8/17/2023 | 55220.42 |
| 8/18/2023 | 55220.42 |
3 Replies
- JoeBarrySolution Sage
Hi cyborgandy
Do you have a date table in your dataset with a relationship to this Fact table? Please try below
Lets say the table above is called Coverage Table and you have created a measure called Coverage. There is no week available in Power BI, so we will multiple 7 days by 8 weeks to get 56 days to look back.
Measure 1
Avg. Coverage - Last 8 Weeks = VAR NumOfDays = 56 VAR LastCurrentDate = MAX ( 'DIM Date'[Date] ) VAR Period = DATESINPERIOD ( 'DIM Date'[Date], LastCurrentDate, - NumOfDays, DAY) VAR Result = CALCULATE ( AVERAGEX ( VALUES ( 'DIM Date'[Date] ), [Coverage] ), Period ) VAR FirstDateInPeriod = MINX ( Period, 'DIM Date'[Date] ) VAR LastDateWithSales = MAX ( 'CoverageTable'[Date] ) RETURN IF ( FirstDateInPeriod <= LastDateWithSales, Result )Then to add the forecast for two weeks you will need to add this
2 Weeks Forecast = CALCULATE([Avg. Coverage - Last 8 Weeks], DATEADD(DateTable[Date]), - 14, DAY))- cyborgandyHelper II
Hi The above DAX is not working, its not taking coverage column in
AVERAGEX ( VALUES ( 'DIM Date'[Date] ), [Coverage] ),
- JoeBarrySolution Sage
Hi cyborgandy
It should be correct as I am using a similar measure in my Reports. When I created the measure, I refered to this article. https://www.sqlbi.com/articles/rolling-12-months-average-in-dax/
Thanks
Joe