I have a table with products (Cols E-F) from 3 countries (Col A), with weekly values (Cols H-L) and condition (Col G) based on which I need to aggregate the weekly values, and also display the aggregation logic. Columns 44-48 are week numbers, hence these should be treated as dynamic columns.
Current table:
| Country | Producer | Packaging | Brand | SAP code | Material Description | AGG condition | 44 | 45 | 46 | 47 | 48 |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | x | x | x | 11111 | product 1 | sum of all 3 | 1.1 | 1.1 | 1.1 | 1.1 | 1.1 |
| 2 | x | x | x | 11111 | product 1 | sum of all 3 | 1.1 | 1.1 | 1.1 | 1.1 | 1.1 |
| 3 | x | x | x | 11111 | product 1 | sum of all 3 | 1.1 | 1.1 | 1.1 | 1.1 | 1.1 |
| 1 | y | y | y | 22222 | product 2 | sum of countries 1+2 | 2.2 | 2.2 | 2.2 | 2.2 | 2.2 |
| 2 | y | y | y | 22222 | product 2 | sum of countries 1+2 | 2.2 | 2.2 | 2.2 | 2.2 | 2.2 |
| 1 | z | z | z | 33333 | product 3 | separate | 3.3 | 3.3 | 3.3 | 3.3 | 3.3 |
| 2 | z | z | z | 33333 | product 3 | separate | 3.3 | 3.3 | 3.3 | 3.3 | 3.3 |
| 3 | z | z | z | 33333 | product 3 | separate | 3.3 | 3.3 | 3.3 | 3.3 | 3.3 |
Desired output:
I've tried multiple options, but unfortunately can't get desired result. What would be the proper M code?

