Walgreens Boots Alliance (WBA 0.47%) reported third-quarter earnings last week, and investors were down on the results. The stock fell to a new 52-week low as the company's sales and profits declined from the previous year. While that isn't great news to hear, there's more to the story. Let's dig in.

Sales were down, but they weren't a disaster

For the period ended May 31, revenue declined 4.2% year over year to $32.6 billion. But a big part of that is due to its pharmacy sales in the U.S., which were down 9.7% during the period. The company's comparable retail revenue in the U.S. rose by 2.4% when excluding tobacco. And internationally, sales grew slightly by 0.3% year over year to $5.3 billion.

Overall, the company's top line was better than the $32.06 billion that analysts were expecting. It was by no means catastrophic, especially given that in prior periods the healthcare company received significant boosts in traffic due to COVID-19 vaccinations. Although it's still administering these shots, Walgreens notes that vaccine volumes hit their peak a year ago.

Profits tanked due to a couple of large items

Investors may have also soured on is the company's net earnings of $229 million, which were a  fraction of the nearly $1.2 billion that Walgreens reported a year ago. But as displayed in the chart below, there were two glaring areas responsible for the drop in net income: selling, general and administrative (SG&A) expenses, and equity investments.

Source: Company filings. Chart by author.

A big chunk of the bump in SG&A this past quarter was due to $683 million in expenses that Walgreens incurred in relation to an opioid settlement in Florida.

Meanwhile, earnings from "equity method investments" -- that is, large positions Walgreens has taken in the shares of other companies -- totaled just $5 million this past quarter versus $575 million in the prior-year period. Walgreens also enjoyed a $424 million gain from a partial sale of its investment in AmerisourceBergen.

When stripping out these various non-operating items, which can fluctuate from one period to another, Walgreens' bottom line doesn't look nearly as bad; its adjusted per-share profit of $0.96 was better than the $0.92 Wall Street was expecting.

Another positive takeaway from the company's recent earnings report is an expected improvement in long-term profitability. Through a transformational cost management program, Walgreens expects that by fiscal 2024, it will achieve annual cost savings of $3.5 billion -- higher than the $3.3 billion it was previously forecasting.

Is Walgreens a buy?

The opportunity to buy Walgreens at a new 52-week low is attractive given that the stock now pays a yield of around 5%. That's far better than the S&P 500 average of 1.7%. Shares of the healthcare company are now down 26% this year, performing worse than the broader index, which has fallen by 20%. 

Walgreens isn't in such bad shape as the stock's sell-off suggests. The company's fundamentals remain sound -- and it could make for an underrated buy right now.