Forum Discussion
Matrix calculation with multi-layered SUMX
Hi there
I have been struggling with the Matrix Calculation for years, and SUMX + VALUES seems to be most handy way that can cover most situations. However as you can below it won't help when there are more than 2 layers of context (i.e. LP_ABBR (customer name), MonthDate and ProductLine5 here)... The displayed outcome are obviously wrong... Need your help on it. Thanks!
9 Replies
- ahadkarimi
Solution Specialist
Hi yamacha, try this SUMMARIZE, if you encounter any issues, let me know.
ERROR_LP_PLS = SUMX( SUMMARIZE( ACTUAL_LP, LP_ABBR[LP_ABBR], TIME[MonthDate], MASTER_PL[ProductLine5], "ActualQty", SUM(ACTUAL_LP[Actual Qty]), "ForecastQty", SUM(FCST_LP[FCST Qty]) ), ABS([ActualQty] - [ForecastQty]) )Did I answer your question? If so, please mark my post as the solution!✔️
Your Kudos are much appreciated! Proud to be a Responsive Resident!- yamacha
Helper I
Thanks ahadkarimi
I created two columns (end with Neo) with your codes as below. As only 'ACTUAL_LP' is summarized in your code so it will miss the lines w/o actual demand but still with forecast, and ultimately underestimate the error.
- AnonymousNot applicable
Hi All,
Firstly ahadkarimi thank you for your solution!
And yamacha to my understanding,you want to get the error for each product line for that month and then add that up, right?
The matrix can be aggregated for you, you don't need to write your own aggregation function, maybe my data is too simple to reproduce your problem, if you can can you upload some sample data, maybe it will help to solve your problem.ERROR_LP = ABS(SUM('basic data'[Actual Qty])-SUM('basic data'[FCST Qty]))I would be extremely proud if I could solve your problem and look forward to hearing from you!
Hope it helps!
Best regards,
Community Support Team_ Tom ShenIf this post helps then please consider Accept it as the solution to help the other members find it more quickly.
- yamacha
Helper I
Hi Xingshen
Thanks for the comments, but unfortunately it's not that simple. There is a further layer below the product line that is the UPN (SKU), and I need to calculate the error on these 2 different levels (that's why you see I have to columns for Error).
- AnonymousNot applicable
Hi yamacha ,
I apologise for not providing you with a suitable solution as I didn't understand you correctly.
If sumx and value may not be able to calculate the value of the difference between the strata correctly, you can use the alexecpt function to add a qualification to determine the stratum you need to calculate-- ERROR_LP_PL5 = CALCULATE( MAXX( VALUES('Table'[ProductLine5]), ABS(SUM('Table'[Actual Qty]) - SUM('Table'[FCST Qty])) ), ALLEXCEPT('Table', 'Table'[LP_ABBR], 'Table'[MonthDate], 'Table'[ProductLine5]) )-- ERROR_LP_UPN = CALCULATE( MAXX( VALUES('Table'[UPN]), ABS(SUM('Table'[Actual Qty]) - SUM('Table'[FCST Qty])) ), ALLEXCEPT('Table', 'Table'[LP_ABBR], 'Table'[MonthDate], 'Table'[ProductLine5],'Table'[UPN]) )If in doubt, check out the pbix file I uploaded and I'd be honoured if I could help you out!
Best regards,
Community Support Team_ Tom ShenIf this post helps then please consider Accept it as the solution to help the other members find it more quickly.