STOCKHOLM (Reuters) - Sweden's H&M HMb.ST posted its first rise in quarterly pretax profit in more than two years on Thursday as the world's second-biggest fashion retailer said its drive to meet rapid changes in the market were on track.

H&M has been spending heavily on reviving its business after years of falling profits and growing inventories due to slowing sales at its core H&M branded stores.

Shares in H&M, which is controlled by the founding Persson family, with the founder’s son the chairman and his grandson the CEO, were up 6.5% at 1040 GMT.

“H&M delivered its first strong quarterly earnings in over four years, which could raise confidence in the turnaround,” investment bank Carnegie said in research note.

After hitting a 13-year low in 2018, the shares have soared 56% this year on hopes H&M is starting to get back on track, though they remain at about half their peak levels hit in 2015.

Pretax profit for the June to August quarter beat expectations, rising for the first time since the second quarter of 2017, to 5.0 billion crowns ($507 million) from 4.01 billion a year ago. Analysts had on average forecast a rise to 4.93 billion crowns, Refinitiv data showed.

“The continued development of more full-price sales and reduced markdowns contributed to a 26% increase in operating profit in the third quarter, all while maintaining a high level of activity in our transformation work,” CEO Karl-Johan Persson said in a statement.

FILE PHOTO: An H&M sign is seen at the entrance to an H&M store in Palma on the island of Mallorca, Spain June 14, 2019. REUTERS/Anna Ringstrom/File Photo

Profit growth was also helped by accelerating sales growth.

H&M had said on Sept. 16 that sales growth in the quarter was the steepest in three years buoyed by well-received summer ranges and increased market share. But analysts cautioned that investment might again squeeze profit margins, and shares fell on that day.

H&M’s gross margin actually widened to 50.8% from 50.3%, and its operating profit margin rose to 8.0% from 7.1%.

Zara owner Inditex ITX.MC, H&M's biggest rival, has been weathering challenges in the sector better than most yet its first-half results on Sept. 11 revealed disappointing margin growth that overshadowed a strong rise in sales.

Smaller brick-and mortar rival Forever 21 filed for bankruptcy on Sept. 30.

H&M’s inventories increased 9% to 42.0 billion crowns at the end of its third quarter, equivalent to 18.5% of sales. However, H&M said that, measured in local currencies, they shrank by 1% while the composition of the stock had kept improving.

The group in 2018 announced a target to cut inventories to 12-14% of sales by the end of 2020. CEO Persson told Reuters on Thursday that H&M still aims for that range, but no longer has a timeframe for it.

Price cuts to shift unsold clothes decreased for a fourth straight quarter, by 2 percentage points in relation to sales. H&M in June had predicted a 1.5 percentage point decrease. The company unusually did not provide an outlook for markdowns in the current quarter.

H&M said sales in September, the first month of its fourth quarter, grew 8% in local currencies. Persson told analysts and media on a call that favorable weather had helped boost sales.

“We believe we have reached an inflection point for margins and foresee the potential for further markdown recovery over the next 2-3 years,” said RBC analyst Richard Chamberlain, who recently raised his rating on H&M to “outperform”.

Executives also said on the call that activity to transform the company would remain high in coming quarters and Persson said investment levels would stay elevated.

Analysts however still expect H&M to grow full-year profits, for the first time since 2015.