I interpret you problem as having values in column P that are different than the values in column K but both sets of values are attached to the values in column M and that you want the sum of the values that match R2 and W2. You should limit the length of the ranges instead of having whole columns.
Formula:
=SUMPRODUCT(--(P:P=R2),M:M)+SUMPRODUCT(--(K:K=W2),M:M)
Bookmarks