Back in December, Costco Wholesale (COST 1.09%) reported an impressive 7.5% increase in adjusted comp sales for the first quarter of its 2019 fiscal year. But the stock plummeted because Costco's gross margin declined significantly in the quarter.

Not surprisingly, the pressure on Costco's gross margin didn't last long. Last week, the warehouse club giant posted stellar earnings growth for the second quarter of fiscal 2019, even though its sales growth moderated. Investors should expect more of the same in the future: Gross margin will be unpredictable from quarter to quarter, but relatively stable over the long term, while sales growth will continue to outpace the broader economy by a wide margin.

A strong quarter for Costco

Comps rose 5.4% at Costco last quarter, or 6.7% after adjusting for the impact of gasoline price deflation, foreign currency fluctuations, and new revenue-recognition rules. Net sales rose 7.3% to $34.6 billion for the quarter. Membership fee revenue also increased 7.3%, reaching $768 million.

Meanwhile, gross margin improved to 11.3% from 11% a year earlier. This -- combined with Costco's solid revenue growth -- caused operating income to surge 18% to $1.2 billion. Costco also benefited from an improvement in net interest expense and a slightly lower tax rate, mainly due to foreign tax credits. The net result is that Costco's earnings per share skyrocketed 26% to $2.01. This dramatically exceeded the average analyst estimate of $1.69.

Check out the latest earnings call transcript for Costco.

The entrance to a Costco warehouse

Costco's earnings per share smashed analysts' estimates last quarter. Image source: Costco Wholesale.

It's (almost) all about gas prices

Costco's gross margin expansion last quarter was driven by strength in what the company calls its ancillary businesses. These businesses boosted gross margin for Costco as a whole by 33 basis points (with 100 basis points equaling 1 percentage point).

Richard Galanti, Costco's long-serving CFO, noted that most of the margin improvement in the ancillary businesses came from Costco's gas stations. Costco gets about 10% of its revenue from gasoline sales, and margins depend heavily on price trends. Price declines (like the big plunge seen last fall) tend to temporarily boost Costco's gross margin on gasoline sales. Of course, rising gasoline prices have a corresponding negative impact on gross margin.

The growth of Costco's e-commerce business made a smaller contribution to the company's gross margin improvement, but Galanti did not quantify the amount, other than to say that it was much smaller than the tailwind from higher gasoline margins.

Comparing each of Costco's main merchandise categories to itself a year earlier, core gross margin improved by 8 basis points last quarter. On the same basis, core gross margin declined by 6 basis points in the first quarter. But while there was some underlying improvement sequentially, Galanti said there was no big trend change -- just the normal small fluctuations you would expect from quarter to quarter.

Looking ahead

There are two big takeaways from Costco's second-quarter earnings report. The first is that the company's 26% surge in EPS was basically a fluke. Declining gas prices, a small uptick in core gross margin, some foreign tax credits, and elevated membership fee growth related to Costco's 2017 price increase all combined to boost EPS growth last quarter.

The second big takeaway is that Costco's subpar first-quarter earnings results were equally a fluke. (Operating income actually declined slightly in that quarter.) Investors had no reason to panic three months ago.

The reality for Costco is somewhere between its apparently dismal first quarter and its apparently stellar second quarter. As a company with about $150 billion of annual revenue that operates on narrow margins, very small changes in Costco's margin structure can have an outsize impact on its earnings growth.

The good news for investors is that Costco largely controls its own destiny. The company is constantly working to lower prices for customers, something that has driven strong sales growth and fostered enormous loyalty over the years. By tweaking pricing from time to time, Costco can ensure that its profit margin stays roughly constant. As long as the top line keeps surging, investors shouldn't worry too much about Costco's performance.