Question to "Heroic Victory"

I had many many campaigns in Empire Total war and sometimes i dont really understand how the Victory Message at the End of a Battle works. At times, i decimatet Armies without taking many losses and got it and sometimes i nearly lost the battle, yet withstand with the same Endmessage. Sometimes i won easily and i got "Close Victory" besides i havent even lost a quarter of my entire Army. How does this work or is it just random?