Microsoft co-founder Bill Gates extended his lead yesterday over Mexico’s Carlos Slim as the world’s richest person to $5.1 billion, according to the Bloomberg Billionaires Index.

Almost all of Gates’s investments, including a 4.8 percent stake in Redmond, Washington-based Microsoft, have soared this year while Slim’s main holding, a 44 percent stake in America Movil SAB, the largest mobile-phone operator in the Americas, has fallen 14 percent.

One of the biggest gainers in Gates’s portfolio, which he controls through his Kirkland, Washington-based investment vehicle Cascade Investment LLC, is Ecolab Inc. The St. Paul, Minnesota-based provider of sanitation and health services is up 22 percent this year, a performance that has added $423 million to the billionaire’s fortune.

“Ninety percent of what they produce gets flushed down the drain and you have to rebuy it,” Shlomo Rosenbaum, an analyst at Stifel Nicolaus & Co.’s Baltimore office, said in a telephone interview. “They have repositioned their portfolio of assets to be much more exposed to the energy market. That’s something that I think will help their top-line growth for years to come.”

Gates, 57, has a net worth of $72.9 billion, according to the Bloomberg ranking. Slim, 73, controls a $67.8 billion fortune, down $7.4 billion so far this year amid America Movil’s fall.

Other gainers in Gates’s portfolio include Phoenix-based waste disposal company Republic Services Inc., which is up 18 percent year-to-date, and Montreal-based Canadian National Railway, which has risen 17 percent. Together, the two holdings have increased Gates’s net worth by more than $1 billion.

Funded by years of Microsoft dividends and share sales, Cascade controls stakes in more than two dozen publicly traded and closely held companies. Bridgitt Arnold, a spokeswoman for Gates, said he declined to comment.

Microsoft, which hit a five-year high last week, is up more than 31 percent for the year, adding $3.3 billion to Gates’s fortune.

Cascade, which the billionaire solely owns, also controls 4,350 Class A shares of Omaha, Nebraska-based Berkshire Hathaway Inc. Warren Buffett, the company’s chairman, is the world’s third-richest person. He has a $60 billion net worth.

Gates and Buffett started the Giving Pledge campaign in 2010 to encourage philanthropy among the rich. The initiative has 114 signatories who have committed to donate at least half of their fortunes to charity, according to its website.