What happened

It may not sound like much, but Walmart (WMT -1.75%) had a pretty good month in April as its stock price rose 2.7%, according to S&P Global Market Intelligence.

When you consider the fact that the S&P 500 was down 8.8% -- its worst month since the start of the pandemic -- and the Nasdaq Composite was down 13.3% for the month, a 2.7% return looks pretty good. The nation's largest retailer is up about 3% year to date as of May 6.

A person shopping in a box store, looking up, smiling.

Image source: Getty Images.

So what

While most of the market was down, including online retail giant Amazon, Walmart bucked the trend with its positive return in April. As a discount retailer, Walmart is a more affordable option for consumers, particularly during times of high inflation. For context, during the 2008-2010 market downturn, Walmart posted a return of nearly 17%, while the S&P 500 was down 20% over that period, as my colleague Keith Noonan pointed out in a recent article.

The other thing that Walmart benefited from is a solid dividend, which boosts its total return. It raised its quarterly dividend to $0.56 per share, which paid out in early April. It is the 49th straight year that the company has raised its dividend, putting it one year away from being a Dividend King -- 50 straight years of dividend raises.

Also in April, Walmart released its annual report for its fiscal year (FY), which ended Jan. 31. It posted revenue of $572 billion, up 2.4% over FY 2021 with U.S. comp sales (comparable store) up 6.4% year over year. The e-commerce business did $73 billion in sales for the year, an increase of 11% over the previous fiscal year. On a two-year stack, e-commerce sales are up 90%.

Now what

Walmart's valuation has come down in recent months, as it currently has a price-to-earnings ratio of 31, down from 48 at the end of its fiscal year on Jan. 31. That's still a bit high, but the forward P/E is a more reasonable 22. Also, its price-to-sales is also low at 0.75, right around where it has been for the past year or so.

There is a lot of uncertainty in the market right now, with interest rates rising and the potential for recession, but Walmart is built to perform well in periods like this, relative to the market, and would provide some good ballast to a portfolio.