Well, the Soviet military were actually achieving their aims.
When the Soviet Union fell, the Soviet military had plenty of dead or live but traumatized young men courtesy of their Afghan enemies, but less than the Americans suffered due to Vietnam - the Soviet involvement in Afghanistan was never as heavy as that of the US in Vietnam. (The US lost 4 times as many KIA as the Soviets did mainly because they sent 3 times as many men into Indochina in the course of their involvement.)
I'm not sure how economic losses would compare.
The Afghan Communists controlled all the major cities by the end of the 80s, and once the Soviets pulled their own troops out, showed they had the morale and organizational grip to keep winning their civil war. The indications were that so long as the Soviets maintained subsidies and political comfort, the Afghan regime could win.
So it is quite likely (though not completely certain) that the Soviet Union had won the battle for Afghanistan and then snatched defeat from the jaws of victory when they lost the war for the hearts of their own people.
It is unlikely that the Soviets actually killed more Afghans than the US killed Vietnamese, but it is possible.
Estimates of Afghan civilian deaths range between 562,000 and 2 million. Mujahideen deaths were between 75-90 thousand. Estimates of total Indochinese deaths (differentiating between military and civilian was harder in the American wars in Indochina) range from 1,450,000-3,595,000 deaths. So it is possible that the Soviet-Afghan violence killed half a million more than the American-Indochinese violence did. Alternatively, the Americans may be directly or indirectly responsible for 3,000,000
more deaths than the Soviets.
Almost certainly the reason for the large dip in the Afghan population graph is due to a combination of people fleeing the country and people dying. (The Soviet-Afghan war resulted in 5 million fleeing Afghanistan and a further 2 million being internal refugees.)
EDIT: Also, the Russian military did a pretty good job of learning from their mistakes in Afghanistan, even considering the institutional disruption of the collapse of the USSR - better, IMO, than the US learned from Vietnam. Most of the reasons why we worry about Putin's reformed military today are rooted in changes that began in the aftermath of Afghanistan.
fasquardon