Over the past five years, Walmart (WMT -0.08%) shares have climbed 70%, easily beating the 48% gain of Home Depot (HD 0.94%). Perhaps more noteworthy is that the former is near its all-time highs, while the latter is currently 25% below its peak price from December 2021. There's clearly a divergence happening with each company's performance lately. 

From an investment perspective, there are some important details to be aware of before deciding which of these top retail stocks is the better buy. Here's what investors need to know. 

Banking on business from professionals

After experiencing a surge in demand during the worst days of the pandemic, Home Depot's business is seeing a notable slowdown. The leadership team points to weaker consumer spending, and a shift away from goods to services, that has resulted in revenue declining 2% in the recently completed second quarter, ended July 30. And management believes sales will drop 3.5% (at the midpoint) for the full year. 

But despite the latest troubles, Home Depot possesses a long-term track record of solid revenue and earnings growth that should ease investor concerns. As the economy gets back on solid footing, the company should return to normalized growth. 

Roughly 50% of Home Depot's sales come from professional customers, like contractors, electricians, and plumbers. This compares quite favorably to the breakdown of its chief rival, Lowe's, which gets just 25% of its revenue from this important customer cohort. Compared to do-it-yourself (DIY) consumers, pros spend more per visit. And this helps explain why Home Depot has consistently posted better margins and return on invested capital than Lowe's. 

The stock currently trades at a trailing price-to-earnings (P/E) ratio of 19.6. That's below the five-year trailing average, and it's a discount to what Lowe's is selling for now. Making the situation better for investors is the fact that Home Depot returns lots of cash back to shareholders in the form of dividends and buybacks, totaling more than $9 billion in just the first six months of fiscal 2023. Maybe now is a good time to adopt a long time horizon and take advantage of the opportunity. 

Grocery sales are a pillar of strength

Whereas Home Depot is seeing its business slow down dramatically, Walmart has posted healthy gains. Revenue and adjusted diluted earnings per share rose 5.7% and 4%, respectively, in the fiscal 2024 second quarter (ended July 28), both of which exceeded analyst estimates. Same-store sales in the U.S. were up 6.4%. And the online segment was a key strength as e-commerce sales soared 24%. The leadership team is so optimistic that they actually raised guidance for the current fiscal year. 

Walmart's recent performance highlights how resilient the company is in the face of macro headwinds, like higher interest rates and still-elevated inflation. Consumers are clearly interested in saving money when they shop, putting Walmart in a favorable competitive position. Moreover, because the business has such a huge presence in the grocery category (Walmart is the largest grocer in the U.S.), it is somewhat protected from not only recessionary periods, but also the ongoing threat of digital rivals. 

Even though this is already a massive enterprise, investors should be encouraged by the growth prospects. According to Wall Street consensus estimates, Walmart is forecast to increase revenue at a compound annual rate of 3.8% between fiscal 2023 and 2028. That's nearly double the estimated 2% annualized clip projected for Home Depot. Additionally, Doug McMillon, Walmart's CEO, believes earnings are set to rise even faster than the top line going forward. 

Because the stock is close to its all-time high, it's not necessarily cheap, trading at a trailing P/E multiple of about 31. But that valuation might be appropriate for investors seeking a safe business to own. 

The final word 

Both Home Depot and Walmart are very mature businesses, so investors shouldn't expect double-digit revenue growth from either of them. However, they are leaders in their respective industries. 

On the one hand, Home Depot has the edge because of its more attractive valuation. But Walmart's growth potential is better if Wall Street forecasts hold any weight. 

Consequently, it's ultimately up to investors to decide whether they prefer to focus on growth or value when choosing between these retail behemoths for their portfolios.