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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Calculating value for future month based on previous month

Hi, 

I have measure (measure 1) which calculates a value for each month. I wish to calculate a forecast for the coming month based on the previous the average for the last 1, 2 and 3 month but not later then todays month. E.g. 

MonthMeasure1Forecast measure to  be (correct)My current forecast measure (wrong)
Aug 20202  
Sept 20202  
Oct 20203  
Nov 2020 2,33

2,33 (average of aug, sep, oct)

Dec 2020 2,33

1,67 (average of sep, oct and nov)

Jan 2021 2,33

1 (average of oct, nov and dec)

 

At the moment I use this forecast measure: 


=
Var
FrvLM = CALCULATE([FraværsdagsværkPrÅrsværk], DATEADD(Calender[Date], -1, MONTH)) 

Var
frv2MAgo = CALCULATE([FraværsdagsværkPrÅrsværk], DATEADD(Calender[Date], -2, MONTH)) 

Var
frv3MAgo = CALCULATE([FraværsdagsværkPrÅrsværk], DATEADD(Calender[Date], -3, MONTH)) 

RETURN
DIVIDE(FrvLM + frv2MAgo + frv3MAgo, 3, 0)


Thanks! 
Mikkel

1 ACCEPTED SOLUTION
DataInsights
Super User
Super User

@Anonymous,

 

Try these measures:

 

Total Amount = SUM ( TestData[Amount] )

Forecast = 
VAR vLastDateMeasure = LASTNONBLANK ( ALL ( 'Date'[Date] ), [Total Amount] )  --get last date where measure is not blank
VAR vEndDate1 = EOMONTH ( vLastDateMeasure, 0 )
VAR vStartDate1 = DATE ( YEAR ( vEndDate1 ), MONTH ( vEndDate1 ), 1 )
VAR vEndDate2 = EOMONTH ( vLastDateMeasure, -1 )
VAR vStartDate2 = DATE ( YEAR ( vEndDate2 ), MONTH ( vEndDate2 ), 1 )
VAR vEndDate3 = EOMONTH ( vLastDateMeasure, -2 )
VAR vStartDate3 = DATE ( YEAR ( vEndDate3 ), MONTH ( vEndDate3 ), 1 )
VAR vMonth1Measure =
    CALCULATE (
        [Total Amount],
        DATESBETWEEN ( 'Date'[Date], vStartDate1, vEndDate1 )
    )
VAR vMonth2Measure =
    CALCULATE (
        [Total Amount],
        DATESBETWEEN ( 'Date'[Date], vStartDate2, vEndDate2 )
    )
VAR vMonth3Measure =
    CALCULATE (
        [Total Amount],
        DATESBETWEEN ( 'Date'[Date], vStartDate3, vEndDate3 )
    )
VAR vVisualRowDate = MAX ( 'Date'[Date] )  --get date from row in table/matrix visual
VAR vAverage = DIVIDE ( vMonth1Measure + vMonth2Measure + vMonth3Measure, 3 )
RETURN
    IF ( vVisualRowDate > vEndDate1, vAverage, BLANK () )  --display average for future months

 

Date table is 'Date', and should be joined to the data table (TestData).

 

DataInsights_0-1602956311358.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

3 REPLIES 3
DataInsights
Super User
Super User

@Anonymous,

 

Try these measures:

 

Total Amount = SUM ( TestData[Amount] )

Forecast = 
VAR vLastDateMeasure = LASTNONBLANK ( ALL ( 'Date'[Date] ), [Total Amount] )  --get last date where measure is not blank
VAR vEndDate1 = EOMONTH ( vLastDateMeasure, 0 )
VAR vStartDate1 = DATE ( YEAR ( vEndDate1 ), MONTH ( vEndDate1 ), 1 )
VAR vEndDate2 = EOMONTH ( vLastDateMeasure, -1 )
VAR vStartDate2 = DATE ( YEAR ( vEndDate2 ), MONTH ( vEndDate2 ), 1 )
VAR vEndDate3 = EOMONTH ( vLastDateMeasure, -2 )
VAR vStartDate3 = DATE ( YEAR ( vEndDate3 ), MONTH ( vEndDate3 ), 1 )
VAR vMonth1Measure =
    CALCULATE (
        [Total Amount],
        DATESBETWEEN ( 'Date'[Date], vStartDate1, vEndDate1 )
    )
VAR vMonth2Measure =
    CALCULATE (
        [Total Amount],
        DATESBETWEEN ( 'Date'[Date], vStartDate2, vEndDate2 )
    )
VAR vMonth3Measure =
    CALCULATE (
        [Total Amount],
        DATESBETWEEN ( 'Date'[Date], vStartDate3, vEndDate3 )
    )
VAR vVisualRowDate = MAX ( 'Date'[Date] )  --get date from row in table/matrix visual
VAR vAverage = DIVIDE ( vMonth1Measure + vMonth2Measure + vMonth3Measure, 3 )
RETURN
    IF ( vVisualRowDate > vEndDate1, vAverage, BLANK () )  --display average for future months

 

Date table is 'Date', and should be joined to the data table (TestData).

 

DataInsights_0-1602956311358.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Anonymous
Not applicable

Thanks @DataInsights!

It works perfectly. One last adjustment. My "LASTNONBLANK" can be a month in 2021 as month can be filled out in advance. How can I change the the "vLastDataMeasure" to be today instead?

Best,
Mikkel

@Anonymous,

 

Glad to hear that works. You can change it as follows:

 

VAR vLastDateMeasure = TODAY ()





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.