Inflation is bringing a new crowd of shoppers to Walmart: high-income earners looking for low grocery prices. It has provided a boost to the retail giant's market share in this product category.

Walmart CFO John David Rainey told CNBC this week that about 75% of the company's market share in second-quarter grocery revenue came from customers with an annual family income north of $100,000.

Walmart's jump in the grocery market share and better inventory management helped the company earn $1.77 EPS in the most recent quarter on $152.9 billion in revenue. Both figures are higher than analysts' estimates, sending the company's price of shares sharply higher on Wall Street.

For years, Walmart was the destination for low and middle-income shoppers, who sought low prices to balance the family budget. Soaring inflation in recent months has changed that, as Walmart has become a shopping destination for all income demographics.

"Walmart showed modest upside surprise in its Q2 earnings, albeit against previously lowered estimates for revenue and EPS," Derek Wittenberg, Managing Director at Progress Partners, told International Business Times in an email.

"Management highlighted strength in the grocery category as many consumers, against the inflationary backdrop, stepped back from bigger-ticket purchases such as televisions and furniture to focus on staples and back-to-school shopping.

"In addition, in the face of inflation-driven increases in everyday items like meat, produce, and eggs, consumers are stretching their spending dollar by trading down in quantity and quality as well as buying more canned goods such as tuna, chicken, and beans. In particular, the CFO noted increased foot traffic from middle- and upper demographics as many consumers were attracted to Walmart's value pricing."

The problem is that grocery is a highly competitive business with low margins. And that could explain the decline in Walmart's operating margins.

Nonetheless, Pieter de Villiers, CEO at Clickatell, sees this inflation-driven change in consumer shopping patterns as a big opportunity for Walmart.

"Walmart's results are proof that its heavy investments in e-commerce capabilities and building itself as the go-to store for budget shoppers is still working under economic pressures," he told IBT in an email. "However, the inflation-driven shift in consumer spending presents an opportunity for the commerce giant as it navigates through the end of the year."

Meanwhile, Chelsea Wiater, a portfolio manager at EFG New Capital, sees Walmart benefiting from another trend fueled by inflation: "trading down."

"Rainey indicated on their earnings call that the company was starting to see 'more pronounced consumer shifts and trade down activity,' as consumers seek value amidst an environment of sharp macroeconomic pressures," Wiater told IBT in an email.

"This was evidenced by the company's private brand growth rate doubling in Q2 relative to Q1, demonstrating that these macro pressures have worsened as the year has progressed. Furthermore, Rainey indicated this trade-down behavior was the strongest in food categories, indicating that the recession is far from over for the company's core consumers."

But trading down could help Walmart's other businesses, like back-to-school items.

"This concentration of trade-down in food could suggest a dynamic whereby consumers are seeking value in non-discretionary categories so that they can continue to spend in discretionary categories, including back-to-school related items — management called that out as an area of particular strength for Walmart — or categories that have been missing since the onset of the pandemic, such as travel, entertainment, and other services," Wiater said.