Despite being a rich country, the US has a surprisingly wide wealth disparity. Walmart targets the lower end of that wealth gap. It seems that Walmart struggles in countries with a smaller wealth gap (at least w/r to local economics).
Though the reason Walmart failed in Germany is most likely due to the strong competition by ALDI and Lidl and its effects on the competitiveness (and profit margins) of other German supermarket chains.