The only way from Barcelona to Bergamo is by flight. You should expect to be able to find tickets starting around $344, if you search flights from BCN to BGY. The best time to book long flights is 5-6 weeks before your trip.
On your trip from Barcelona to Bergamo, it is best to book as soon as possible. It won't necessarily help reduce your price by a large amount, but will ensure that you have a spot on the bus or train.