Big-name retailers such as Walmart are increasingly using analytics to blunt the impact of one of the most unpredictable performance variables of shopping: weather.

Weather data, once used strictly for inventory planning, is now helping retailers localize advertising and decide when to discount seasonal items such as sweaters.

Walmart, whose inventory planning with artificial-intelligence software incorporates weather analysis, reduced sunscreen prices a couple weeks earlier than usual this year in parts of the U.S.