If we find out about it decades or centuries out. If it's a year out when we spot it, there's very little we can do with current technology to head it off (asteroid disaster movie plots notwithstanding).
> And if self sustaining is all you need, setting up a self-sustaining colony a mile underground is also five or six orders of magnitude cheaper.
It's also much more accessible by desperate refugees trying to get in as the planetary disaster approaches.
What makes SpaceX important is that they've rethought the design and manufacturing process to make their rockets far cheaper than others to date. If you bend the cost curve enough, surprising things become reasonable.
For comparison, the space station cost $150 billion 2010 dollars (according to Wikipedia). It is in low-earth orbit and satisfies no conditions of self-sustainability. With a factor of 100 on that, which is impossibly optimistic, you are already at $15 trillion.
I can't think of any risk to humanity where going to the moon or Mars makes sense as insurance.