计算平均绝对百分比误差时未给出正确的平均值。

huangapple go评论110阅读模式
英文:

Not giving the correct average while calculating the Mean Absolute Percentage Error

问题

I am analyzing a forecast and a station data. During the night, I am getting negative values on the station, and zero values on the forecast data. And there are some days I am missing some data.

Keeping that in mind, I am trying to calculate the Mean Absolute Percentage Error (MAPE) in DAX within Power BI to compare my forecast values to my station data. If there is a value equal or less than 0, or there is not any value, then do nothing. However, I am not getting the correct average for my MAPE. Here's how I am currently calculating it:

MAPE =
VAR Actual =
    AVERAGE ( STATION_TABLE[GHI] )
VAR Forecast =
    AVERAGE ( FORECAST_TABLE[GHI] )
VAR AbsoluteError =
    ABS ( Actual - Forecast )
RETURN
    IF (
        OR ( Actual <= 0, Forecast <= 0 ),
        BLANK (),
        DIVIDE ( AbsoluteError, Actual )
    )

I am then averaging the MAPE for all of my data points using the following measure:

MAPE_Average = AVERAGE([MAPE])

I made a table with the date, hour, station data, the forecast data, and the MAPE result to compare the result. The MAPE is correct until it calculates the average.

However, when I compare this value to the MAPE total calculated using other tools (such as Excel), I am getting a different average. The average on the table is the value MAPE result of the TOTAL AVE values at the end of the table. So, I am not getting the average of the whole column. And the measurement, which I did apart, is giving another result which is not the same in Excel and neither the table.

Can anyone help me identify what I might be doing wrong, or suggest an alternative approach for calculating the MAPE in DAX?

Here I will add one day as an example:

If we check the total average, it should be 13.52%, not 9.45%, which is the MAPE between 226.95 and 205.50.

英文:

I am analysing a forecast and a station data. During the night, I am getting negative values on the station, and zero values on the forecast data. And there are some days I am missing some data.

Keeping that in mind, I am trying to calculate the Mean Absolute Percentage Error (MAPE) in DAX within Power BI to compare my forecast values to my station data. If there is a value equal or less than a 0, or there is not any value, then do nothing. However, I am not getting the correct average for my MAPE. Here's how I am currently calculating it:

MAPE =
VAR Actual =
    AVERAGE ( STATION_TABLE[GHI] )
VAR Forecast =
    AVERAGE ( FORECAST_TABLE[GHI] )
VAR AbsoluteError =
    ABS ( Actual - Forecast )
RETURN
    IF (
        OR ( Actual <= 0, Forecast <= 0 ),
        BLANK (),
        DIVIDE ( AbsoluteError, Actual )
    )

I am then averaging the MAPE for all of my data points using the following measure:

MAPE_Average = AVERAGE([MAPE])

I made a table with the date, hour, station data, the forecast data and the MAPE result to compare the result. The MAPE is correct until it calculate the average.

DATE HOUR STATION_DATA FORECAST_DATA MAPE
01/01/2023 00:00 - - -
01/01/2023 01:00 - - -
01/01/2023 02:00 - - -
............ ............ ............ ............ ............
05/01/2023 10:00 55 - -
05/01/2023 11:00 56 - -
05/01/2023 12:00 89 - -
............ ............ ............ ............ ............
07/01/2023 10:00 - 45 -
07/01/2023 11:00 - 78 -
07/01/2023 12:00 - 100 -
............ ............ ............ ............ ............
08/01/2023 13:00 -5.0 45 -
08/01/2023 14:00 -4.6 78 -
08/01/2023 15:00 -5.1 100 -
.......... ............ ............ ............ ............
09/01/2023 12:00 45 49 8.89%
09/01/2023 13:00 56 51 8.93%
09/01/2023 14:00 105 120 14.29%
- - TOTAL AVE: 300 TOTAL AVE: 309 TOTAL: 3.0%

However, when I compare this value to the MAPE total calculated using other tools (such as Excel), I am getting a different average. The average on the table is the value MAPE result of the TOTAL AVE values at the end of the table. So, I am not getting the average of the whole column. And the measurement, which I did in apart, is giving another result which is not the same in Excel and neither the table.

Can anyone help me identify what I might be doing wrong, or suggest an alternative approach for calculating the MAPE in DAX?

Here I will add one day as example:

DATE HOUR STATION_DATA FORECAST_DATA MAPE
01/01/2023 00:00 -5.21 0 -
01/01/2023 01:00 -5.24 0 -
01/01/2023 02:00 -5.17 0 -
01/01/2023 03:00 -5.22 0 -
01/01/2023 04:00 -5.07 0 -
01/01/2023 05:00 -5.43 0 -
01/01/2023 06:00 16.94 15.5 8.52%
01/01/2023 07:00 146.43 130 11.22%
01/01/2023 08:00 292.26 323 10.52%
01/01/2023 09:00 515.99 505.5 2.03%
01/01/2023 10:00 669.63 663.5 0.92%
01/01/2023 11:00 782.34 735 6.05%
01/01/2023 12:00 914.03 761 16.74
01/01/2023 13:00 659.63 683.5 3.62%
01/01/2023 14:00 572.60 491 14.25%
01/01/2023 15:00 549.93 344.5 37.36%
01/01/2023 16:00 321.52 219.5 31.73%
01/01/2023 17:00 74.38 60 19.34%
01/01/2023 18:00 -5.40 0 -
01/01/2023 19:00 -6.28 0 -
01/01/2023 20:00 -6.76 0 -
01/01/2023 21:00 -6.47 0 -
01/01/2023 22:00 -6.28 0 -
01/01/2023 23:00 -6.31 0 -
TOTAL 226.95 205.50 9.45%

If we check the total average, it should be 13.52% a not 9.45% which is the MAPE between 226.95 and 205.50.

答案1

得分: 0

Measure_2 =
SUMX(
VALUES('Fact Table_TIME'[Hour]),
IF(
[MAPE] > 0, [MAPE]
)
)/12

其中的 12 是列 [MAPE] 中值的计数。

英文:

I found the answer but it can't be applied in all cases, I just create a new measure that call the measure I posted before:

Measure_2 = 
SUMX(
    VALUES('Fact Table_TIME'[Hour]),
    IF(
       [MAPE] > 0, [MAPE]
    )
)/12

The 12 is the counts of values in the column [MAPE]

huangapple
  • 本文由 发表于 2023年3月8日 19:04:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/75672190.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定