SEATTLE — The uncertainty and challenges in the global economy have hit Microsoft, which on Tuesday reported quarterly earnings that fell short of Wall Street’s and its own expectations.

The tech giant said it had $51.9 billion in sales in the quarter ended June 30, up 12 percent from a year earlier. Profit rose 2 percent to $16.7 billion.

The results missed even Microsoft’s own reduced expectations. In early June, the company lowered its guidance for the quarter to account for the increasingly strong U.S. dollar.

“We’re obviously incredibly bullish on just about everything else that we have,” Chris Capossela, the company’s marketing chief, said after the revised guidance was released. “That’s one thing we can’t control.”

Since then, the conditions appear to have deteriorated further. The foreign currency challenges spurred by the war in Ukraine and broader economic uncertainty cost Microsoft $595 million in the quarter as it converted sales in Europe, Japan and elsewhere back into U.S. dollars. And production slowdowns of personal computers in China and falling consumer demand caused a decline of more than $300 million in sales of its Windows operating system that comes preinstalled on new computers.

A slowdown in advertising spending on LinkedIn and on Microsoft’s search products caused more than a $100 million decline in revenue.

Were it not for currency problems, Microsoft’s flagship cloud computing platform, Azure, would have grown 46 percent. Instead, it grew 40 percent, short of what investors expected. Without the strengthening dollar, the company’s two main enterprise lines of business, which it calls Productivity and Business Processes, and Intelligent Cloud, would have met the initial guidance it provided investors in April.

“Commercial demand overall felt pretty healthy,” Brett Iversen, Microsoft’s head of investor relations, said in an interview on Tuesday. “The long-term thesis of people wanting to move to the cloud to digitize their business, to be able to do more or to be able to save money — all of that still feels intact.”

He said that was reflected in strong long-term bookings commitments, including a record number of Azure deals worth more than $1 billion.

Overall revenue for Microsoft’s commercial cloud computing offerings, which also includes Office 365 subscriptions, increased 28 percent to $25 billion.

“We are not immune to what is happening in the macro broadly,” Satya Nadella, the company’s chief executive, said in a call with Wall Street analysts. But he said the continued interest that businesses have in using cloud services, which bills in part based on consumption, reflects companies efforts to make do with less.

“Moving to the cloud is the best way to shape your spend with demand uncertainty,” he said.

Microsoft’s personal computing business grew 2 percent to $14.4 billion, dragged down by the 2 percent decline in sales of its Windows operating system that comes preinstalled on personal computers. Investors were prepared to see some weakness because shipments of PCs are down from weakened demand and supply chain problems brought on by coronavirus lockdowns in China.

Revenue from Xbox content and services fell 6 percent, as consumers spent less time playing video games.

With unemployment remaining near the lowest levels in 50 years, LinkedIn, the professional social network Microsoft bought in 2016, grew 26 percent, down from 34 percent growth the previous quarter.

The company said it had $126 million in expenses related to scaling down its operations in Russia, and another $113 million in costs for paying severance to employees it laid off.

Mr. Iversen said the layoffs were for “a small number of roles” and the company expected to expand its head count in the new fiscal year, which started July 1.

In the call with Wall Street analysts, Mr. Nadella and Amy Hood, Microsoft’s finance chief, said beyond the strong dollar, the company expected some challenges to persist, such as reduced demand for personal computers, fewer paid job postings on LinkedIn and lower demand from small- and medium-size businesses.

But they said Microsoft would continue investing in markets where it has advantages and expected double-digit revenue growth in the next year, even if foreign exchange headwinds continued. The company’s share price increased about 5 percent in after market trading.