I am trying to use the averageif function, but is there a workaround for the average range

I would like for the average range to take the Total-Available range so something like this (B2 is my Code column, so if the code is the same it will calculate the average

=AVERAGEIF(Code,B2,Total-Available)