It's hard to underestimate Walmart (WMT -1.16%). After all, it's the biggest company in the world by revenue -- and the biggest retailer.

The company is on track to generate more than $550 billion in revenue this year, and after a strong third-quarter earnings report, the retail stock is trading at an all-time high. Year to date, shares have racked up gains of 26%.

A Walmart truck rolling down the highway.

Image source: Walmart.

There's no doubting its market power as a company, but does that mean it's a good stock to buy? The retailer faces challenges on multiple fronts, most notably from Amazon, as the retail industry evolves from brick-and-mortar stores to e-commerce.

Let's take a look at where the retail giant stands to determine how investors should proceed.

An ongoing evolution

In 2015, Walmart CEO Doug McMillon announced that he was raising wages as one of several long-term investments in the company. The stock plunged on the news, but since then, Walmart shares have nearly tripled. Meanwhile, McMillon has shifted the company's strategy from a land-grab mentality focused on blanketing the country with new stores to essentially halting new store openings, instead using its resources to invest in e-commerce and store improvements like grocery pickup stations, inventory management, and better-looking, cleaner stores.

The following year, 2016, the company acquired Jet.com to beef up its e-commerce operations, which now include a fast-growing e-commerce marketplace and the recent launch of the Walmart+ loyalty program. The company has also ramped up its grocery pickup and delivery program, offering pickup from 3,600 stores in the U.S. and delivery from 2,900 locations.

Walmart U.S. has now posted 25 consecutive quarters of comparable-sales growth, a streak that dates back to just a few quarters before McMillon implemented the wage hike.

Meanwhile, the company has made major changes to its international portfolio. It took a majority stake in Flipkart, India's leading e-commerce business, and it owns a 5% stake in JD.com, China's biggest direct online retailer. In the fiscal third quarter alone, the company sold stakes in subsidiaries in the U.K., Argentina, and Japan, showing it's focused on shifting capital away from slow-growth markets and investing in faster-growing areas like India, Mexico, and U.S. e-commerce.

The upshot of those decisions is that Walmart is much better prepared to contend with Amazon and the e-commerce evolution than it was five years ago. Its recent results demonstrate as much. U.S. e-commerce sales rose 79% year over year in the third quarter as the pandemic drove a surge in online orders, and overall U.S. comparable sales were up 6.4%. Profit margins also expanded as the company saw fewer markdowns, leveraged its sales increase, and benefited from increased marketplace sales and an improved product mix in e-commerce. Adjusted earnings per share rose 16% to $1.34.

Is it a buy?

For a stock that's delivered a years-long streak of domestic comparable-sales growth and has a number of competitive advantages, including huge economies of scale and stores within ten miles of 90% of the U.S. population, Walmart shares look reasonably cheap. The stock trades at a price-to-earnings ratio of 22, well below the P/E of the S&P 500 at 36.

Walmart is also a Dividend Aristocrat, having paid increasing dividends for nearly five decades, and offers a dividend yield of 1.4% as of this writing.

With its investment in growth areas like e-commerce, healthcare, and emerging markets like India, plus its competitive strengths that include massive scale and a recession-proof business model, Walmart stock looks almost bulletproof. Its reasonable valuation means that downside risk is limited, and its focus on e-commerce and other attractive markets gives the stock an upside potential that other brick-and-mortar retailers lack.

For investors looking for high-growth stocks, Walmart probably isn't the right choice. But for others, including retirees, dividend investors, and those looking for safe stocks and wealth preservation, Walmart is a solid buy. Pandemic-driven momentum and a smart omnichannel strategy mean the stock should have more gains in store for shareholders.