Regular price tickets cost the same whenever you buy them, whether months in advance or 30 seconds before the train.
You can get deals if you buy your tickets in advance, but there are strings attached. Supersaver tickets are tied to specific trains and aren't available at all time and all routes. They must be purchased on the web (or in the SBB app) and will automatically be offered if available.
The SDP (saver day pass) can be a very good deal as it doesn't tie you to specific trains and is valid on the whole Swiss transport network (well not on mountain railways), but they tend to sell out quickly and as they're dynamically priced, the price gradually increases.