Forum Discussion
yaman123
2 years agoPost Partisan
Calculate Weighted Average for specific attributes
Hi,
I am having difficulty in trying to calculate the weighted average from the dataset I have.
I have unpivoted the data in query editor due to the nature of the data in the source.
I want to work out the total weighted average per column e.g total weighted average for sp £/t, cos £/t and margin £/t. The Total row should show the weighted average
Expected:
| Tonnes | SP £/t | COS £/t | Margin £/t | Margin £k | |
| Downgrade | 50 | 2000 | 3000 | -800 | -50 |
| Mouldy | 0 | 0 | 0 | 0 | 0 |
| Traded | 20 | 4000 | 5000 | -1000 | -30 |
| Total | 70 | 2571 | 3571 | -857 | -80 |
To calculate this for e.g sp £/t, i need to multiply tonnes by the sp £/t value so - ((50 * 2000) + (0*0) + (20*4000))/70
Below is the source table -
| Week No | W/C | Attribute | Value |
| 47 | 20/11/2023 | Downgrade Tonnes | 50 |
| 47 | 20/11/2023 | Downgrade SP £/t | 2000 |
| 47 | 20/11/2023 | Downgrade COS £/t | 3000 |
| 47 | 20/11/2023 | Doiwngrade Margin £/t | -800 |
| 47 | 20/11/2023 | Downgrade Margin £k | -50 |
| 47 | 20/11/2023 | Mouldy Tonnes | 0 |
| 47 | 20/11/2023 | Mouldy SP £/t | 0 |
| 47 | 20/11/2023 | Mouldy COS £/t | 0 |
| 47 | 20/11/2023 | Mouldy Margin £/t | 0 |
| 47 | 20/11/2023 | Mouldy Margin £k | 0 |
| 47 | 20/11/2023 | Traded Tonnes | 20 |
| 47 | 20/11/2023 | Traded SP £/t | 4000 |
| 47 | 20/11/2023 | Traded COS £/t | 5000 |
| 47 | 20/11/2023 | Traded Margin £/t | -1000 |
| 47 | 20/11/2023 | Traded Margin £k | -30 |
Any help is appreciated!
Thanks