Apple keeps getting richer, even though it's selling fewer iPhones than a year ago

Apple reported earnings on Tuesday, and in it revealed how many iPhones it sold during the quarter ending in March.

And the answer is a bit puzzling.

Apple sold 50.76 million iPhones during the quarter, just barely below the 51.19 million sold in the year-ago period.

Yet the company's earnings and revenue are up from a year ago.

In the 2017 March quarter, Apple reported adjusted earnings of $2.10 per diluted share on revenue of $52.9 billion, up from earnings of $1.90 a share on revenue of $50.56 billion this time last year. That has to do with the how the iPhone 7 Plus has boosted the average selling price of Apple's phones: $655, compared to $642 a year ago.

Unsurprisingly, the company has a crazy amount of cash: $256.8 billion, to be exact. And shares are up a whopping 57.5 percent over the past year.

Apple released a special red edition of the iPhone 7 and iPhone 7 Plus this spring. The handsets are the lifeblood of the massive company, which briefly reached a record valuation of over $775 billion on Tuesday.

But the world's most valuable company is having trouble cracking the competitive China market, where sales fell 14 percent from a year ago. Cook told investors on a conference call that he expected that market to improve, but not come back to growth.

Some people may also be delaying smartphone purchases in anticipation of a new, fancier forthcoming phone, chief executive Tim Cook told CNBC.

But a mix of more expensive phones and other products and services is helping the company supplement its flattening iPhone shipments.

Apple boss Tim Cook said the that the iPhone 7 Plus sales were "extremely strong."

"We are having significant growth rates beyond what we ever dreamed of," Cook said of the higher-priced model. He added in a conference call, though, that prior generations iPhones didn't perform as well in China.

The iPhone 7 Plus, which ditched the headphone jack and featured a souped-up dual camera, is being closely tracked as a precursor to the next iPhone, expected to hit in the autumn and potentially feature major upgrades like wireless charging and 3-D sensing.

Apple is also seeing some revenue growth from some unexpected places.

Other products, like the much-maligned Apple TV, Apple Watch and AirPods, saw revenue jump 31 percent from a year ago. And services, like AppleCare and the App Store, saw 18 percent growth. Even the Mac saw double-digit growth during the quarter.

Apple has planned to revamp its stores, in part to draw in services spending.

Still, services, Mac and other products combined only provide about half the level of revenue as the iPhone.