I have a large data set which involves the return for a category as well as its benchmark. I wish to find the correlation or beta between the two. The given formula is COVARIANCE.P(stock return, index return)/VAR.P (Index Return), however as i have large number of stocks (categories), i also have mutiple benchmark returns, which apply to different stocks. Is there a formula which will select the data for this formula by matching the two categories. Eg a domestic share to the domestic share index.
I have attached an example and looking for any suggestions.