cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
MIchri
Resolver I
Resolver I

Cálculo del valor para el mes futuro basado en el mes anterior

Hola

Tengo medida (medida 1) que calcula un valor para cada mes. Deseo calcular un pronóstico para el mes siguiente basado en el anterior el promedio para los últimos 1, 2 y 3 meses, pero no más tarde entonces el mes de hoy. E.g.

MesMedida1Medida de previsión a ser (correcta)Mi medida de previsión actual (equivocada)
Agosto 20202
Septiembre 20202
Octubre 20203
Nov 2020 2,33

2,33 (promedio de aug, sep, oct)

Dic 2020 2,33

1,67 (promedio de sep, oct y nov)

Ene 2021 2,33

1 (promedio de oct, nov y dec)

En este momento utilizo esta medida de previsión:


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

Fue
frv2MAgo - CALCULATE([Frav-rsdagsv-rkPr-rsv-rk], DATEADD(Calender[Date], -2, MONTH))

Fue
frv3MAgo - CALCULATE([Frav-rsdagsv-rkPr-rsv-rk], DATEADD(Calender[Date], -3, MONTH))

devolución
DIVIDE(FrvLM + frv2MAgo + frv3MAgo, 3, 0)


¡Gracias!
Mikkel

1 ACCEPTED SOLUTION
DataInsights
Super User II
Super User II

@MIchri,

Pruebe estas medidas:

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

La tabla de fechas es 'Date' y debe unirse a la tabla de datos (TestData).

DataInsights_0-1602956311358.png

View solution in original post

3 REPLIES 3
DataInsights
Super User II
Super User II

@MIchri,

Pruebe estas medidas:

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

La tabla de fechas es 'Date' y debe unirse a la tabla de datos (TestData).

DataInsights_0-1602956311358.png

View solution in original post

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

@MIchri,

Me alegra oír que funciona. Puede cambiarlo de la siguiente manera:

VAR vLastDateMeasure - HOY ()

Helpful resources

Announcements
PBI User Groups

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

March Update

Check it Out!

Click here to read more about the March 2021 Updates!

secondImage

The largest Power BI virtual conference

100+ sessions, 100+ speakers, Product managers, MVPs, and experts. All about Power BI. Attend online or watch the recordings.

secondImage

Experience what’s next for Power BI

See the latest Power BI innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Top Kudoed Authors