I got 3 group which is ministry, implementer and program. I need to calculate the average value of program that are not null.

The problem is, I found that the calculation is incorrect when using all the data, but if i test it 1 by 1 data its run properly