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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
LucasD
Frequent Visitor

Forecast Versions and lag calculations

Every month, we generate a forecast for the next 6 months.

When the month ends, the version of the forecast is stored as the version of that month.

I would like to create a measure that returns what was forecasted for that month in the previous version.

 

The table looks like this:

Date MonthForecast VersionForecast in KGs
2024032024038
2024042024035 (x)
202405

202403

4

2024062024036
2024072024039
20240820240310
20240420240411
2024052024047 (y)
2024062024046
2024072024047
2024082024048
2024092024049
2024052024056
2024062024053 (z)
2024072024058
2024082024051
2024092024053
2024102024052

 

The measure should return:

 

Date MonthForecast Lag -1
202403 
2024045 (x)
2024057 (y)
2024063 (z)
202407 
202408 
202409 
202410

 

 

If easier for the measure, you could use Date Month and Forecast Version as if they were a Date (date can be Start or End of Month)

Thanks in advance!

1 ACCEPTED SOLUTION
LucasD
Frequent Visitor

Hey,

Found the solution. I did the following:

 

Created a calculated column called "Lag"

 

Date MonthForecast VersionForecast in KGsLag
01/03/202401/03/202480
01/04/202401/03/202451
01/05/202401/03/202442
01/06/202401/03/202463
01/07/202401/03/202494
01/08/202401/03/2024105
01/04/202401/04/2024110
01/05/202401/04/202471
01/06/202401/04/202462
01/07/202401/04/202473
01/08/202401/04/202484
01/09/202401/04/202495
01/05/202401/05/202460
01/06/202401/05/202431
01/07/202401/05/202482
01/08/202401/05/202413
01/09/202401/05/202434
01/10/202401/05/202425

Where Lag is =DATEDIFF(Table1[Forecast Version],Table1[Date Month],MONTH)

 

The measure then looks like this:

 

Forecast Lag - 1:=CALCULATE(SUM([Forecast in KGs]),Table1[LAG]=1)

 

Results:

Date MonthForecast Lag - 1
01/04/20245
01/05/20247
01/06/20243

View solution in original post

4 REPLIES 4
LucasD
Frequent Visitor

Hey,

Found the solution. I did the following:

 

Created a calculated column called "Lag"

 

Date MonthForecast VersionForecast in KGsLag
01/03/202401/03/202480
01/04/202401/03/202451
01/05/202401/03/202442
01/06/202401/03/202463
01/07/202401/03/202494
01/08/202401/03/2024105
01/04/202401/04/2024110
01/05/202401/04/202471
01/06/202401/04/202462
01/07/202401/04/202473
01/08/202401/04/202484
01/09/202401/04/202495
01/05/202401/05/202460
01/06/202401/05/202431
01/07/202401/05/202482
01/08/202401/05/202413
01/09/202401/05/202434
01/10/202401/05/202425

Where Lag is =DATEDIFF(Table1[Forecast Version],Table1[Date Month],MONTH)

 

The measure then looks like this:

 

Forecast Lag - 1:=CALCULATE(SUM([Forecast in KGs]),Table1[LAG]=1)

 

Results:

Date MonthForecast Lag - 1
01/04/20245
01/05/20247
01/06/20243
Anonymous
Not applicable

Hi @LucasD ,

 

Try formula like below:

Forecast Lag -1 = 
VAR CurrentMonth = MAX('Table'[EndOfMonth])
VAR CurrentVersion = MAX('Table'[Forecast Version])
VAR PreviousVersion = CurrentVersion -1
var Len_ = LEN(MAX('Table'[Forecast in KGs]))
RETURN 
    CALCULATE(
        MAX('Table'[Forecast in KGs]),
        FILTER(
            'Table',
            Len_> 2 
            && 'Table'[Forecast Version] = PreviousVersion
        )
)

vkongfanfmsft_0-1716792743656.png

 

Best Regards,
Adamk Kong

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

gmsamborn
Super User
Super User

Hi @LucasD 

 

Would these measures help?

 

Forecast = SUM( 'Table'[Forecast in KGs] )

Same Month - Previous Version = 
    CALCULATE(
        [Forecast],
        OFFSET (
            -1,
            ALLSELECTED ( 'Table'[Forecast Version] ),
            ORDERBY ( 'Table'[Forecast Version], ASC )
        )
    )

Lag = [Forecast] - [Same Month - Previous Version]

 

 

I hope I understood your requirement.

 

Same Month - Previous Version.pbix

 



Proud to be a Super User!

daxformatter.com makes life EASIER!

Hi, thanks for your reply.

That did not work, as the offset is including all planning versions but the last. So, it is including the values of two planning versions at the same time. What I need is to include only one, the next planning version.

 

I made it work by creating two calendar tables (one for the forecast version and one for the date month) and included a rank for the months.

 

Then the formula I used, which can't explain how it works (but works) is this one:

 

FCT T-1 =
VAR VersionMonth = DATEADD(CalendarTablePlanningVersion[DateId],0,MONTH)
VAR ForecastMonth = DATEADD(CalendarTableForecastDateMonth[DatesId],0,MONTH)
RETURN
CALCULATE([Forecast],VersionMonth,ForecastMonth,CalendarTableForecastDateMonth[Ranking]=CalendarTablePlanningVersion[Ranking]+1)

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.