ZN() function is used to convert nulls to 0 for any measure. it is used because if we perform multiplication or division there should not be arithmetic exception.
Talking about below section (partial)
(ZN(AVG([AAA Ratio])) - LOOKUP(ZN(AVG([AAA Ratio])), -1))
This will take the Avg AAA ratio and subtract it from the Avg AAA ratio from previous row.
lookup(SUM([Number of Records]),-0)
After getting above answer it will be multiplied with total number records by each value in dimension. I am not sure why its written as -0. - and 0 I have never seen them together. Correct me if I am wrong.
If possible, please share the sample data I can explain things on it.