When Walmart (WMT 0.46%) cut its guidance three weeks ago, it sent shudders through the market.

The S&P 500 fell more than 1%, and investors saw it as the latest sign that the economy was slumping into a recession. After all, Walmart controls around $500 billion in annual spending in the U.S., or nearly 10% of all non-automotive retail dollars. More than any other company, Walmart has its finger on the pulse of the economy, and in addition to being the biggest retailer in the world, it's also the world's biggest private employer, giving it outsize influence over the labor market as well.

Now, just three weeks later, Walmart is painting a much different picture. The retail giant posted better-than-expected results in its second-quarter earnings report. Comparable sales came in at 6.5%, ahead of guidance at around 6%, and its operating margin was 4.5%, compared to its earlier forecast of 4.2%. Operating income also declined just 7%, compared to the forecast three weeks ago of 13% to 14%.

Walmart also raised full-year guidance after second-quarter results came in better than expected. It now sees a decline in adjusted earnings per share of 9% to 11%, compared to a previous range of 11% to 13%.

On the earnings call, management explained that "strong sales at the end of the month (July) with good flow-through to the bottom line and lower-than-expected supply chain cost." That's a sign that the economy and Walmart's prospects have brightened in just the last three weeks. Though its guidance still calls for a profit decline in the second half of the year, that's more about markdowns to reduce excessive inventory than headwinds in the economy. In fact, those markdowns should help fuel the consumer recovery and lower inflation.

Home Depot ain't too shabby either

Walmart isn't the only indicator worth watching in the retail sector. Home Depot (HD 0.74%) is the biggest home improvement retailer in the U.S., representing a significant percentage of consumer discretionary spending, or about $130 billion in annual U.S. revenue.

After two blowout years during the pandemic, Home Depot expected sales growth to moderate in 2022, but the second quarter delivered another round of strong results. Comparable sales rose 5.8% in the quarter, or 5.4% in the U.S., driving revenue up 6.5% to $43.8 billion, ahead of estimates at $43.36 billion. That was also better than the company's full-year comparable sales guidance at 3%.

On the bottom line, earnings per share increased 11% to $5.05, ahead of the consensus at $4.95. Even more encouraging was that the company saw positive comps in all regions of the U.S., and same-store sales jumped 7.1% in July, showing the business is accelerating into the third quarter.

What it means for investors

Home Depot and Walmart both posted solid gains on the reports, up 4% and 5% respectively Tuesday, but the market mostly shrugged off the message for the broader economy, as the S&P 500 increased just 0.2%.

Investors should also remember that the reports from two of the U.S.'s biggest retailers come as other economic data shows the economy seems to be turning the corner away from a potential recession. The U.S. economy added more than half a million jobs last month. Unemployment is near record lows at 3.5%. Inflation is starting to ease, and oil prices have already come down substantially, which is a boon to both consumers and businesses that have been absorbing higher-than-normal fuel prices.

Aside from the inventory gluts that are leading to markdowns, both retailers look to be in solid shape for the second half of the year, and the strong comparable sales growth at both brands indicates that consumers are as well.