Surging grocery prices have a lot of consumers shopping more at Walmart (WMT -0.52%) to take advantage of its low prices.

But inflation is also pressuring everyone to become more mindful of what they purchase at the big-box store. Some may forego big purchases in order to ensure they have enough room in the budget to put food on the table. And Walmart makes a lot more money on discretionary items like toys and electronics than it does on weekly grocery runs.

The challenge for Walmart is to translate its expanding customer base into expanding profits. Let's see what this could mean for investors.

Finding new customers

Despite being a market leader in the grocery space, management says it's still gaining share of grocery purchases. Customer transactions increased 5.7% year over year in Walmart's U.S. stores last quarter. That outpaces the overall grocery industry, which has seen trips increase about 2%.

The market share gains are coming from all types of households, including the wealthy. Nearly 75% of the company's market share gains in the grocery industry came from households with more than $100,000 in annual income, management said on its third-quarter earnings call.

But those customers are focused on groceries and staples. Food sales grew at a mid-teens percentage growth rate in the third quarter, management said. Meanwhile, sales of general merchandise declined at a low single-digit rate, with particular weakness in electronics, home, and apparel.

That trend points to a significant challenge at Walmart. First of all, its new shoppers are overwhelmingly focused on its grocery business. On top of that, existing Walmart shoppers are eschewing general merchandise purchases to make room in the budget for groceries, which have seen prices balloon in the last couple of years.

Filling up the shopping cart

In order for Walmart to succeed long term, it needs to convert its new shoppers from grocery-only shoppers to general merchandise shoppers.

To that end, Walmart is struggling. When asked if those higher-income consumers coming to Walmart for groceries are shopping for general merchandise at all, management didn't have an affirmative answer. In fact, the CEO of Walmart U.S., John Furner, practically told analysts that getting those shoppers to use the Walmart app and shop across all of its products remains an opportunity for the business.

But when it comes to general merchandise, Walmart has much bigger competition. It's able to beat local grocery chains on pricing thanks to its scale, and it's positioned to accept thinner margins on groceries to attract customers to its higher-margin merchandise. But it can't always beat customers on general merchandise pricing.

And the same trend that's leading more shoppers to look to Walmart for their groceries is also likely leading them to shop around at other retailers for their more discretionary purchases. That's especially true as more shopping moves online to e-commerce.

Impacting the bottom line

The shift in consumer spending is having a meaningful impact on Walmart's bottom line. Groceries have very thin gross margin profiles. The goal is to make up for those thin margins with volume.

While Walmart is growing the volume of groceries it sells, it's also seeing higher-margin general merchandise sales fall. On top of that, inventory challenges have Walmart discounting general merchandise where it can, leading to further drops in gross profits.

The result is a growing top line, but a declining bottom line. And management isn't entirely optimistic that it'll turn those growing sales into profits anytime soon. Its outlook for the fourth quarter called for flat operating income compared to a year ago and a decline in earnings per share between 3% and 5%.

Until management can show progress in converting grocery shoppers into general merchandise shoppers and improving product mix, top-line growth simply isn't going to cut it for Walmart investors.