In June, UnitedHealth Group (UNH -1.28%) alerted investors that its costs were creeping up due to increasing demand for surgeries. That led to a decline in the share price heading into the company's recent earnings report. But even though the company's medical care ratio -- which measures spending on care as a share of premiums -- increased this past quarter, UnitedHealth still delivered a strong performance. Here's why the company was able to do well and why it continues to be a great buy for growth-oriented investors.

UnitedHealth soundly beat earnings expectations

UnitedHealth reported second-quarter earnings last week, which came in much better than expected. Revenue of $92.9 billion for the period ended June 30 beat analyst forecasts of just over $91 billion. The health insurer also reported adjusted earnings per share of $6.14, which also easily beat Wall Street estimates of $5.99.

The company's medical care ratio did rise from 81.5% to 83.2%, just as investors anticipated, but that wasn't enough to derail the otherwise solid performance for the business. The revenue growth that UnitedHealth generated more than offset the rise in medical expenses and even other operating costs:

UnitedHealth Group waterfall chart showing change in quarterly earnings.

Data source: Company filings. Chart by author.

The company generated $72.5 billion in premium-related revenue last quarter, which was an increase of $8.6 billion from the prior-year period. Medical costs rose by just under $8.2 billion, meaning that UnitedHealth still came in ahead after the rise in expenses and before factoring in revenue growth from its other segments.

The company's strong growth rate has made it an excellent investment

A big reason UnitedHealth has been able to sustain an increase in costs is that the business has become larger and more diversified over the years. Even within just the past year, the company has closed on multiple acquisitions, including home health company LHC Group and analytics business Change Healthcare.

Its revenue growth rate has averaged more than 10% over the past five years, with this past quarter being no exception:

UNH Revenue (Quarterly YoY Growth) Chart

Data source: YCharts

The company's premiums are its largest growth driver, but UnitedHealth also generated $2 billion in additional revenue this past quarter from services and another $1.2 billion in product sales. Even though medical costs related to its premiums may rise as a percentage, the company's diversification enables it to still generate strong profit growth. Adjusted earnings per share rose 10% from a year earlier to $6.14.

Is UnitedHealth stock a buy?

Year to date, shares of UnitedHealth Group are down about 4%. The stock is trading at 23 times trailing earnings, which is slightly lower than the healthcare industry average of 25. But given the company's strong and continued growth prospects, UnitedHealth deserves to be trading at a higher valuation. Even though analysts have lowered their price targets for the healthcare stock recently, UnitedHealth still has a potential upside of about 15% based on the average target of $583.40.

For long-term investors, UnitedHealth remains an excellent stock to buy and hold.