So much for the idea that Walmart (NYSE:WMT) is a boring stock. Shares gained over 40% in 2017 as the retailer added $80 billion to its market capitalization and trounced the broader market. That rally looks even more impressive when judged against industry peers. Target shed 9% in 2017; Kroger shareholders endured a 20% slump; and Wal-Mart roughly doubled Costco's return for the year.

A big factor in that outperformance was investors' low expectations about the retailing giant's business. And with much more optimism attached to the stock today, it will be harder for Walmart to surprise Wall Street in 2018. Still, the year ahead should include sales records and significant cash returns, tempered by sluggish profits and a brutal fight for market share.

More traffic online and offline

Walmart achieved faster revenue growth the hard way in 2017 -- through increased store traffic. Comparable-store sales accelerated in each of the last two quarters, rising from 1.4% to 1.8% before reaching 2.7% just ahead of the holiday shopping season. Customer traffic held steady over those nine months at a 1.5% gain, just as management hoped it would.

A family walks through the aisles at Wal-Mart.

Image source: Getty Images.

The growth momentum translated to the digital sales channel, too, where revenue was up 50% in the third quarter, compared to a 42% increase for Costco and a 24% boost at Target. These successes demonstrate that the retailing titan has the right pricing strategy to win market share, so shareholders shouldn't be surprised to see healthy sales growth online and in physical stores.

Cash returns are likely to rise as well, thanks to a steadily growing dividend and management's aggressive stock repurchase spending. Walmart returned $14.5 billion to shareholders through these channels in fiscal 2017, compared to $10 billion in the prior year.

Challenges ahead

Even the brightest operating scenario involves some bad news for the business, though. Walmart has had to spend lots of cash to build out its online sales infrastructure, even as it allocates more capital toward improving its in-store shopping experience. Thanks to these rising expenses, operating income worsened to $16 billion, or 4.4% of sales, from $16.5 billion, or 4.7% of sales, over the first three quarters of fiscal 2018. Walmart's free cash flow is down significantly, too, at $10 billion compared to $12 billion. In other words, while the company is enjoying faster growth, it's paying a price for that success.

WMT Operating Margin (TTM) Chart

Data by YCharts.

Competition won't be letting up in 2018, either. Kroger recently abandoned its long-term annual profit targets while vowing to cut prices as much as necessary to protect its market share. Target is also chasing value-focused shoppers and is allowing its profitability to sink in the process. Costco, meanwhile, is logging its fastest customer traffic growth in years and has aggressive plans to expand its store base and its online offerings.

Walmart won't have to beat all of these rivals for the stock to make a decent investment in 2018. But given the huge 2017 rally, investors will likely be disappointed if they don't see evidence that spending aimed at improving the in-store and online shopping experiences is delivering modestly increasing market share and rising profits. 

This article represents the opinion of the writer, who may disagree with the “official” recommendation position of a Motley Fool premium advisory service. We’re motley! Questioning an investing thesis -- even one of our own -- helps us all think critically about investing and make decisions that help us become smarter, happier, and richer.