The second quarter's earnings season has been hit-and-miss thus far for the broader market, with poor guidance doing more damage than last quarter's results. Although not quite in dire straits, consumers and corporations alike are clearly watching their spending.

This mindful spending is a big reason discount retailer Walmart (WMT -0.08%) did so well in Q2 -- the company offers much-needed low prices. Revenue was up 5.4% year over year on a constant-currency basis for the three-month stretch ending in July, while same-store sales in the U.S. improved to the tune of 6.4%. Operating income was up 17.3%, and adjusted earnings of $1.84 per share is a healthy improvement on the year-ago comparison of $1.77. That growth says the company isn't completely powerless when it comes to combatting inflation.

Perhaps the most exciting aspect of Walmart's second-quarter numbers, though, is one of the numbers nobody's really talking about. That's its advertising business, made possible by the growing number of visitors to Walmart.com. Ad revenue grew by 35% year over year.

Retail media advertising boasts big profit margins

That was a 35% improvement on how much money? Great question. Walmart's Q2 report didn't say, and management didn't add any additional details during the second-quarter conference call. The company likely wants to avoid disclosing too many details to competing retailers about its budding retail media ad business -- advertisements paid for by brands looking to promote their products to Walmart's online shoppers. It didn't offer up any specific dollar amounts with its Q1 results either, except to point out that advertising sales grew 30% year over year during the quarter.

The information is out there, however, if you do some digging. In its fourth-quarter report posted in February, Walmart said it did $2.7 billion worth of advertising business in 2022. That's an average of $675 million per quarter. Last quarter's 35% growth of this business would put the quarterly figure somewhere in the ballpark of just under $1 billion.

It's not a massive amount of money compared to Walmart's annualized sales of more than $600 billion. However, there are two important details about Walmart's revenue worth noting. First, its massive retail business is a low-margin one. The average operating profit margin rate for the past four reported quarters is a mere 4.1%, translating to net income of only $14 billion.

Second (and conversely), profit margin rates for the company's digital advertising business are likely much, much higher. While Walmart doesn't divulge the exact numbers, digital revenue tends to boast profit margin rates anywhere between 50% and 90%, depending on the company. Walmart's retail media advertising business is likely to be producing comparable profits. And that puts something Walmart CFO John David Rainey said in March of this year back in focus.

Walmart is preparing for the shift

Speaking at an investor conference hosted by Raymond James, Rainey explained earlier this year, "Today, the vast majority of our overall profits are attributable to in-store brick-and-mortar in the U.S." He goes on to say, however, "If you fast forward five years, we are much less dependent on that as an income stream than some of these other faster-growing parts of our business."

He wasn't explicitly talking about digital advertising.

Except, maybe he was talking about digital ads. In the very same presentation, Rainey concedes, "The more eyeballs that are coming to your digital platforms, the more advertisers want to spend money." He then went on to point out that retail media advertising profit margins usually fall in the 70% to 80% range, arguably implying that Walmart's are in the same ballpark as industrywide norms.

That's still not a huge amount of money. Assuming 75% of Walmart's annual digital ad business, currently worth around $3 billion, is turned into profit, it's still only around $2.25 billion, or about 15% of its current pre-tax bottom line.

It's certainly not chump change, though. It's also only the beginning.

See, e-commerce only accounts for around 13% of Walmart's current yearly top line, according to numbers from market research outfits Oberlo and Forrester. The other 87% of its business is still done in-store, when and where the purchasing decision is made. Although it's unlikely the retailer will ever do 100% of its business online, there's a massive opportunity to shift much of its current offline business to Walmart.com, where it can then generate more ad revenue.

That's a prospect Walmart's management seems to understand, too. Rainey went on to comment at the Raymond James conference, "The common thread through all of them [all of its differing profit centers] is a greater digital engagement with our consumer." These sound like the words of a man on a mission to reduce his employer's dependence on traditional retailing profits by increasing its reliance on digital advertising profits.

The bullish case for Walmart stock is stronger than it seems

Just as it does with other brick-and-mortar retailers, Walmart is competing for digital ad dollars. Both Amazon and Google parent Alphabet are in the business, along with Kroger, to name a few.

There may be enough opportunity for all of them to grow this sliver of their top and bottom lines, though. Insider Intelligence estimates the U.S. retail media market will double in size between now and 2027, growing from this year's expected $45.2 billion to $106.1 billion at the end of the four-year timeframe. Market research outfit GroupM believes the worldwide retail media advertising market will eclipse the TV advertising market by 2028. That's huge.

Bottom line? Nobody's exactly been struggling to find a reason to buy Walmart stock. Indeed, the company seems to be benefiting from the challenging economic environment, with more and more high-income consumers shopping in its stores in search of lower prices. Sales and earnings growth prove it.

Given the overlooked profit-growth prospects linked to its digital advertising business, though, the reasons to buy Walmart stock are even stronger than they seem with just a passing glance.