How to set up calculations based on conditions?