cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
jessicarocha
Advocate II
Advocate II

Calculate Mean Absolute Error using columns from 4 tables

Hi guys,

 

I've been trying to calculate the MAE but I am having some problems. I think the solution could have something to do with the summarize function but I am not sure how to use it here. 

 

MAE  = abs (actuals - forecast ) / number of observations

 

With my current formula, I am summing all the actuals per subsidiary, then summing all the actuals per forecast and calculating the difference. However, I would like to calculate this difference per month. Then, only in the end, to aggregate per subsidiary. 

 

I also tried to use SUMX but it did not work. I think i need to create some temporary table with summarize in order to get the correct results. Can you please help me? 

Thanks in advance.

Dummy data is in the drive for download.

 

https://drive.google.com/drive/folders/1eejhJ_zFyWfpGz2SS9iu6WnQIlfFLpQr?usp=sharing 

 

jessicarocha_0-1635174717450.png

 

4 REPLIES 4
parry2k
Super User
Super User

@jessicarocha Hey sorry, I saw your file afterward and I realized that columns are in different fact tables.

 

Try this measure:

 

Measure New = 
VAR __table = 
CROSSJOIN ( 
    CALCULATETABLE(VALUES ( 'Dim Subsidiary'[Subsidiary] ), 'Fact Current Data' ),
    CALCULATETABLE( VALUES ( 'Dim Date'[Date] ), 'Fact Current Data' ) 
)
VAR __data = 
ADDCOLUMNS ( 
    __table, 
    "@Historical", CALCULATE ( SUM ( 'Fact Current Data'[History] ) ), 
    "@Forecast", CALCULATE ( SUM ( 'Fact Historical Data'[Forecast] ) ) 
) 
RETURN
SUMX ( __data, ABS ( [@Historical] - [@Forecast] ) ) 

 

Follow us on LinkedIn

 

Learn about conditional formatting at Microsoft Reactor

My latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.






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

Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.





Hi @parry2k . Thank you so much for the help! Sorry for the delayed answer, I was sick.

So, your measure solved a part of my problem. It calculates the Absolute Percentage Error (APE) per Subsidiary and month correctly. But when I aggregate per subsidiary, something is wrong....
In addition, I would like to calculate the Mean absolute percentage error(MAPE). Basically just the APE divided by the number of observations (N). In this case, 3. 

I think the number of observations I was able to get it right with this measure:

Test N = 

    Calculate(
      DISTINCTCOUNT('Dim Date'[Year Month]),
        
    FILTER(
        'Fact Historical Data','Fact Historical Data'[Forecast done in]= min('Fact Historical Data'[Forecast done in]) 
        ),
    FILTER('Dim Date', 'Dim Date'[Fiscal Year] = "2021/22"),
    FILTER('Fact Current Data', 'Fact Current Data'[History] <> BLANK())
    )

So it is just missing the aggregation of your metric to be correct by subsidiary. Can you help me with that?

Thank you so much!

Kind regards, Jéssica


2021-11-04 08_48_57-Dummy - Power BI Desktop.jpg



parry2k
Super User
Super User

@jessicarocha maybe add a different column first and then sum it up:

 

Difference Column = Table[History] - Table[Forecast]

Difference Measure = SUM ( Table[Difference Column] )

Avg = DIVIDE ( [Difference Measure], COUNTROWS ( Table ) ) 

 

Follow us on LinkedIn

 

Learn about conditional formatting at Microsoft Reactor

My latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.






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

Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.





Thanks for the answer @parry2k. How can I create this column since the two variables are in different tables?
I thought about a calculated column but it is not working. My two variables are in different fact tables that are not direct connected to each other. But they could be connected using the Dim Subsidiary and Dim Date....

Thanks. 

Greetings, Jéssica


Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Power BI Dev Camp Session 23 768x460.jpg

Check it Out!

Mark your calendars and join us on Thursday, June 30 at 11a PDT for a great session with Ted Pattison!

June 20 episode 7 with aka link 768x460.jpg

The Power BI Community Show

Join us on June 20 at 11 am PDT when Kim Manis shares the latest on Azure Synapse analytics, the Microsoft Intelligent Data Platform, and notable Power BI Updates from Microsoft Build 2022.

Top Solution Authors
Top Kudoed Authors