Even as the broader market has slumped 17% this year, Walmart (WMT 0.43%) is one of the few stocks showing some signs of life. Though the retail giant has battled some major highs and lows recently as investors weigh the probability of a recession and its impact on retail spending, the shares are actually up 5% year to date.

The company's latest quarterly report has put much of investors' concerns at ease. Walmart may still be going strong, but the company has some headwinds to overcome in the near future. Let's take a closer look and see whether or not right now is a good time to buy Walmart.

The case for buying Walmart

Walmart's third-quarter earnings were much stronger than analysts had anticipated. Global sales grew by 8.7%, or 9.8% in constant currency terms, while comparable (comp) sales jumped by 8.2% from last year. Currency fluctuations cut into the company's profit margins, but Walmart still managed to grow international sales by 7.1%.

This prompted the company to raise its full-year guidance, expecting net sales to grow by 5.5% in total. If Walmart achieves this goal, it would be a huge accomplishment considering retail spending has slowed for most operators this year. It would also be a testament to the fact that Walmart's position as a budget retailer helps it maintain a competitive edge despite a slowdown in spending. This could make this stock a valuable buy in the current economy.

We're not currently in a recession, at least not yet. But if one does follow, Walmart's certainly in a favorable position to maintain growth or at least current performance. In past recessions, like the Great Recession, Walmart did a good job maintaining free cash flow (FCF) growth, healthy profit margins, and growing revenues.

While past performance doesn't guarantee future results, there's a good chance the company will continue performing well in a down economy.

The case against buying Walmart

Walmart's projections for the fourth quarter of 2022 and the year to come aren't as optimistic as its recent earnings. It expects to face more currency fluctuations and see a further squeeze on its consolidated operating income. Its gross profit margin has fallen nearly 3% since last year, while its FCF has slipped 37%.

This dip is due to currency losses in addition to having too much inventory. After the pandemic's supply chain shortage and the shopping boom of 2020 and 2021, retailers doubled down on inventory, creating a backlog of products to meet the growing demand from consumers. But spending has slowed, and now retailers are sitting on heaps of inventory.

Products sitting on shelves lead to markdowns, which eat into the company's profits. According to Walmart's third-quarter earnings, it had $12.2 billion in inventory, which was a 12.6% increase from the year before. This is less inventory growth than in prior quarters and is a sign that Walmart is addressing its inventory problem head-on. But high inventory levels at a time when the economy is retracting could lead to trouble ahead. Thinner profit margins mean less revenue and can lead to balance sheet issues if sustained over the long term.

Is Walmart a good buy right now?

Walmart's price-to-sales (P/S) ratio is around 0.6, which is in line with its biggest competitor, Target. Of the two, Walmart is definitely faring better, and it's good knowing its P/S ratio is well within its normal range. Its price-to-earnings of 46 is much higher, though, which indicates the company is currently trading at a premium.

Given the expected slowdown in retail spending and Walmart's inventory problem, it may be advantageous for investors to wait to buy Walmart. If gross profit margins fall further in the coming quarters, its share price could fall with it, providing a more favorable buying opportunity. But there's no guarantee that will happen.

Walmart is still a worthwhile buy right now for long-term investors looking for some stability to ride out the inevitable ups and downs of the market. The stock pays a 1.5% dividend yield, which is in line with the S&P 500, and it's got a fantastic dividend track record to back it. The company has raised its dividend for 20 years and maintains a healthy dividend payout ratio of 68%, which means its dividends aren't in jeopardy of a cut anytime soon.