For the past several months, I have been warning investors about the dangers of investing in Rite Aid (RAD 5.96%). Rite Aid's shares have surged ever higher since late last year, but the company's fundamentals have started to take a turn for the worse.

RAD Chart

Rite Aid 1 Year Price Chart, data by YCharts

Over the past several months, it has become increasingly clear that Walgreen (WBA -0.30%) -- Rite Aid's largest competitor -- is winning back the market share it lost last year during its dispute with Express Scripts. The two drugstore chains reported monthly sales for May this week, and the results confirmed this underlying trend. Walgreen is continuing to bolster its position as the leading drugstore chain in America. Rite Aid, by contrast, looks to be sliding back into its loss-making ways.

Prescription count is key
Both Rite Aid and Walgreen generate most of their revenue from prescription drug sales. The best way to measure prescription market share changes is "same-store prescription count." This measures the percentage change in the number of prescriptions filled in stores that have been open for at least a year. Same-store prescription count is a good proxy for the overall health of a drugstore, because it isn't affected by store openings or closings, or by changes in the mix of name-brand versus generic drugs.

Since Express Scripts customers were unable to fill prescriptions at Walgreens for most of 2012, Rite Aid and CVS Caremark saw steady gains in prescription count. During the first quarter of Rite Aid's FY13 (covering March-May of 2012), same store prescription count increased by 3.0%. During Q2FY13 (covering June-August), same store prescription count increased 4% at Rite Aid. These prescription count gains led to improving profitability, and ultimately allowed Rite Aid to post its first full-year profit since the Great Recession.

However, Walgreen has been working hard to regain customers since reaching a new agreement with Express Scripts, which went into effect last September. It took a while to build momentum, because once somebody switches drugstores, it can be a headache to switch back. However, in the past few months, Walgreen's efforts have really paid off.

In the month of May, Walgreen reported that Express Scripts customers continued to return to its stores, driving a 7.1% increase in same-store prescription count. This was right in line with the pace from March and April; for the full March-May quarter, Walgreen achieved a 7% increase in same-store prescription count.

Clearly, many of the customers coming back to Walgreen were coming from Rite Aid. For the month of May, Rite Aid's same-store prescription count fell by 0.3%. May marked the second straight month of lower same-store prescription counts. For the full quarter, Rite Aid experienced a 0.1% decline in same-store prescription count.

Watch out!
Walgreen shareholders have plenty of reasons to feel good about the company's long-term prospects. Walgreen operates the largest drugstore chain in the country, and customers who left during the Express Scripts dispute seem to be coming back fairly quickly. By contrast, Rite Aid shareholders should be concerned about continuing deterioration in key metrics, like same-store prescription count.

For a while, Rite Aid may be able to maintain its profitability in the face of stagnant sales by closing underperforming locations, and reaping the rewards of generic drug introductions. (Generics are more profitable for drugstores than name-brand drugs.) Longer-term, though, Rite Aid's trend is unsustainable. If customers continue to return to Walgreen, Rite Aid will find itself back where it was in 2010 or 2011: mired in constant red ink. Unfortunately, Rite Aid's FY13 recovery seems more and more like a blip on the radar screen, rather than a sustainable recovery.