Walmart (WMT 1.32%)topped analysts' second-quarter expectations as higher-income shoppers chose the retail behemoth for low-priced essentials. While the company continues to eat up more share of the grocery market, Walmart must first sell through its surplus inventory while contending with inflation's effect on consumer spending.

Higher-income shoppers turn to Walmart

As high inflation reshapes shopping behavior, Walmart's discount prices have lured higher-income shoppers. Focused primarily on lower-priced food and essentials, these more affluent customers boosted Q2 sales numbers remarkably.

According to Walmart's CFO, John David Rainey, roughly 75% of Walmart's market share gains in food were from customers with annual household incomes of $100,000+. Indeed, Walmart continues to eat up more share of the grocery market, as noted in its second-quarter earnings release. 

Sales in established Walmart stores rose 6.5% during the second quarter, more than double the increase observed in the first quarter. Online sales also grew 12% during Q2, a significant increase over the first quarter's online growth of only 1%. These numbers directly reflect the impact inflation has had on consumer behavior and Walmart has been well positioned for this transition.

Dwindling profit margins and overstock

While Walmart's wide selection of products is what makes it unique, keeping inventory levels high has taken its toll on the company's profitability. Walmart reported a profit margin decline of 132 basis points in its Q2 release, citing markdowns and a heavier mix of grocery sales. 

And although Walmart's growing sales of groceries and essentials have been helpful, sales of casual clothing, TVs, and other electronics -- which had previously flown off the shelves during the pandemic -- have dropped substantially. 

Walmart now sits on a large surplus of excess merchandise, and marking prices down to realign inventory levels has "canceled billions of dollars" in revenue, according to Rainey. The recent shift in consumer spending has caused Walmart to lower its profit outlook for the year last month, the first time the company has done so since 2015. 

A strong Q2 and bright outlook

But management remains positive, and the numbers look good. Walmart posted $5.1 billion in net income for Q2, with earnings per share at $1.77 compared to analyst estimates of $1.62. The company's revenue was also higher than expected, at $152.86 billion reported vs. analysts' estimate of $150.81 billion. As previously mentioned, e-commerce sales also rose 12% year over year.

Walmart also reported an excellent quarter for its international business, with positive comparable sales led by Mexico and China. Its global advertising business grew almost 30% in Q2 as well, including Walmart Connect and Flipkart.

Looking to boost memberships to its subscription service, Walmart+, Walmart will include a Paramount+ subscription at no additional cost starting in September. Walmart CEO Doug McMillon expressed that the subscription service is "an important component" of the company's overall growth plan.

Walmart is making progress on offloading its surplus merchandise and also reported that third-quarter back-to-school shopping is off to a strong start. Investors should watch for a solid finish to the back-to-school season and robust holiday sales. If Walmart can sell through its surplus and retain its newfound customer base, potential investors could soon find great value in this discount retailer.