I have a table of data which is originally displayed like this:
I have created a pivot query:
SELECT Ref,
COALESCE([SALES],'N/A') AS [SALES],
COALESCE([PURCHASING], 'N/A') AS [PURCHASING]
FROM
(SELECT Ref,
Sub_Ref,
Division
FROM dbo.Accounts_Download
WHERE Ref = 'MCA042G21AA'
) AS SourceTable
Pivot (MAX(Sub_Ref) For Division in ([SALES],[PURCHASING])) AS CvgPivot
to display the data like this:
However, I have been asked to add in a new field called Profit:
It doesn't seem to matter where I insert the SUM function in my pivot query. I keep coming back to the data being displayed like this:
Any help on how to use multiple aggregations in one pivot query would be much appreciated. As everything I'm doing is coming back to multiple rows. I'd really like the data to be displayed like this: