The formula for the beta of an asset within a portfolio is
where ra measures the rate of return of the asset, rp measures the rate of return of the portfolio, and Cov(ra,rp) is the covariance between the rates of return. The portfolio of interest in the CAPM formulation is the market portfolio that contains all risky assets, and so the rp terms in the formula are replaced by rm, the rate of return of the market.