Apple (NASDAQ: AAPL) has been dethroned from its position as the largest company in the world. In its place rises Microsoft (MSFT -0.18%), although this was a transition many investors saw coming from a mile away.

How did this happen? And is there anything for investors to be concerned about? Let's find out.

Microsoft's AI investments are paying off

Apple took over the title of the world's largest company in 2011. This is assessed by market cap, which is stock price times the number of shares outstanding. From then until now, Apple has briefly lost control of the title from time to time, only to regain it. However, this switch looks to be different.

So far in 2024, Apple's stock has declined 2%, while Microsoft's has risen 8.6%. This shows how investors think of the two companies. While Apple is still strong, it doesn't have the products and strategy to thrive in an artificial intelligence (AI)-fueled market.

On the other hand, Microsoft is highly invested in AI proliferation. First, its partnership with OpenAI (the creators of ChatGPT) aligns it with one of the strongest competitors in the generative AI field. It's using this technology to power its Copilot, which will assist Microsoft Office users in drafting an email, finding formulas for an Excel sheet, or crafting PowerPoints.

For $30 per month, Copilot will provide businesses with the tools they need for their employees to achieve maximum efficiency. This is a fairly small price, especially if it allows businesses to hire one less person per one hundred employees ($30 per month times 100 employees is $3,000 -- less than most office workers' salary).

Microsoft also has a significant foothold in cloud computing. Cloud computing allows its customers to offload workloads to data centers scattered across the globe. This allows clients to easily scale their usage of computing resources up or down -- critical for a company trying to collect as much data as possible to fuel an AI model. Furthermore, when it comes time to create the model, companies need massive computing resources. Most companies don't need to keep a supercomputer at the ready, so it's far cheaper to rent some of Microsoft Azure's computing power than to build a system in-house.

That's just some of the news that's powering the rise in Microsoft's stock. On Apple's side, the situation isn't as bright.

Apple's revenue has fallen for four straight quarters. Demand for its products, including its flagship iPhone, is down, which doesn't bode well for the future.

With Microsoft, there is a lot of hope and excitement around its future. For Apple, many investors hope the situation does not worsen. That's a stark contrast between the two, but there's also something else propelling Microsoft higher.

Both companies are valued at unbelievable levels

Both Microsoft and Apple stocks are quite expensive when assessed on a price-to-earnings (P/E) basis.

AAPL PE Ratio Chart

AAPL PE Ratio data by YCharts

With Microsoft trading at nearly 40 times trailing and 36 times forward earnings, it's way more expensive than Apple (which is pricey in its own right). According to FactSet, the S&P 500 as a whole has a forward P/E ratio of 20 and a trailing P/E of 24.2.

That means Microsoft and Apple trade at an 80% and 46% premium to the market from a forward P/E basis, respectively. That's a hefty premium and may not work out well for the stocks as they look overvalued.

For example, the third-largest U.S. company, Alphabet, has a forward P/E of 23. If it received the same premium as Microsoft (36 times forward earnings), its market cap would rise to $2.99 trillion, nearly tying Microsoft for the world's largest company and passing Apple. Additionally, if Apple and Microsoft had the same valuations, Apple would still hold the title of the largest company on earth by market cap.

This illustrates how much of a stock's rise can be tied to expectations.

While Microsoft's rise is impressive, it has a lot of hype behind its stock. If it doesn't deliver in 2024, don't be surprised if it drops below Apple again. But if it can deliver on the expectations, it will likely cement its place atop the marketplace for some time.