It can feel scary to buy stocks that are plummeting. After all, there's no guarantee they'll come back up. But although it's counterintuitive, buying stocks at lows makes a lot of sense; it gives you more opportunity to see gains.

The trick is to identify which stocks are tanking because they have no future, and which stocks are down because the market is focusing on the short term. In the second scenario, grabbing shares is a sound investing strategy.

Ulta Beauty (ULTA -0.40%) and Williams-Sonoma (WSM 0.17%) are two stocks that are trading at dirt-cheap valuations as they deal with short-term challenges. They look undervalued, and when the market adjusts, investors should gain.

1. Ulta: A differentiated approach to selling makeup

Ulta operates more than 1,300 U.S. stores selling cosmetics, skincare products, and hair care products, as well as providing beauty services. It challenges the traditional dynamics of department store brand versus pharmacy brand versus indie brand by housing all three segments (plus everything in between) under one roof. In doing so, it attracts customers from every demographic and generates high sales and profits.

This has proved to be a popular concept, and Ulta typically demonstrates robust sales growth. What management realized is that most beauty customers don't commit to either cheap or expensive cosmetics, but often buy some of both.

Even expensive cosmetics have low price tags for a luxury item, in contrast to something like housewares or jewelry. A search for mascara on its website brings up the cheapest mascara, which costs $4.99; a $29 version from an indie brand, and many more, most with the same customer rating -- four stars out of five.

A mass-market consumer might choose to spend on a pricey cosmetics or skincare product, while an affluent consumer might go for the cheap eyeliner that has great reviews. Ulta made the genius move to combine this all together and benefit from the gamut of beauty customers. 

Its services are also a big draw, and they add exponentially to the model since services customers are much more likely to buy products as well.

Ulta is still posting strong growth despite the economy. Sales in its fiscal 2023's second quarter (ended July 29) increased 10% over last year while comparable-store sales rose 8%. Earnings per share (EPS) increased from $5.70 last year to $6.02 this year, beating average analyst expectations of $5.85 by a wide margin. Management raised the full-year outlook for sales from a midpoint of $11.05 billion to $11.1 billion.

ULTA Operating Margin (Quarterly) Chart

ULTA operating margin (quarterly) data by YCharts.

However, investors focused on the narrowing of the operating margin, which was 15.5%, down from 17%. For the second consecutive quarter, its operating margin was worse than last year, although the company raised the full-year outlook slightly from a midpoint of 14.75% to 14.8%.

The company is working through the short-term challenges of inflation, and its margin is still higher than historical levels, so it looks like the market is mispricing how this affects Ulta over the long term.

Ulta stock is down 12% this year, and at this price, it trades at 16.5 times trailing-12-month earnings, which is a bargain for this market-beating stock. 

2. Williams-Sonoma: A market beater that pays a dividend

Williams-Sonoma sells upscale housewares and home furnishings, and like other home goods retailers, it's dealing with dual impacts of inflation affecting wallets and the challenge of keeping up with extremely high sales at the beginning of the pandemic. 

It's no surprise that sales are down right now. Comparable-brand revenue decreased 12% in its fiscal second quarter (ended July 30), with two-year comps about flat. That's an indication that this is related to short-term macroeconomic concerns rather than a pattern.

WSM Operating Margin (Quarterly) Chart

WSM operating margin (quarterly) data by YCharts,

EPS fell from $3.87 last year to $3.12 this year but came in well above average analyst expectations of $2.71. The operating margin was 14.6%, down from 17.1% last year and well ahead of pre-pandemic levels. 

In Williams-Sonoma's case, the market rewarded the operating margin, and its stock is up 23% this year. However, it's still down 8% over the past year, and at this price, it trades at the cheap valuation of less than 10 times trailing-12-month earnings.

Management revised its guidance, calling now for lower sales but a higher operating margin. Long-term, the company expects to get back to single-digit sales growth with operating margins above 15%. 

Williams-Sonoma stock has beaten the market for many years, and it pays a dividend that yields 2.4% at the current price. This is an excellent entry point for a stock that should soar again in a bull market.