Pivot Query cant get the correct result

atzdgreat

Member
Local time
Today, 15:50
Joined
Sep 5, 2019
Messages
42
Hi all im trying to achieve the below result with my pivot query but it seems not correct.

TO ACHIEVE:
KPIScoreUserIDKPICodeJuly 2024June 2024
$4.50XXX000035FRACRT04$4.00$5.00
$0.00XXX000172FSACRT01$0.00$0.00
$0.00XXX000172FSACRT07$0.00$0.00

CODE:
Code:
TRANSFORM SUM(Score) AS FinalScore
SELECT AVG(Score) AS KPIScore, UserID, KPICode FROM KPI GROUP BY UserID, KPICode, FORMAT(DueDate, 'MMMM yyyy')
PIVOT FORMAT(DueDate, 'MMMM yyyy')

RESULT:
KPIScoreUserIDKPICodeJuly 2024June 2024
$4.00XXX000035FRACRT04$4.00
$5.00XXX000035FRACRT04$5.00
$0.00XXX000172FSACRT01$0.00
$0.00XXX000172FSACRT01$0.00
$0.00XXX000172FSACRT07$0.00
$0.00XXX000172FSACRT07$0.00
 
Use nz() to force your nulls to 0 values:

 

Users who are viewing this thread

Back
Top Bottom