本末転倒
hon.matsu.ten.tou
Literally: root/origin – tip/end – revolve/turn – fall
Alternately: Putting the cart before the horse. Getting your priorities turned around, or otherwise being mistaken about the relative importance of things. Mixing up cause and effect.
Notes: 本 and 末 are root and branch of a tree; metaphorically this becomes the main and peripheral aspects of something. 転倒 is reversal, flipping, falling. I occasionally misremember this phrase in flipped form as “転倒本末,” which I suppose is appropriate.

A dramatization of what happens inside your head when you do this, I guess. Source.