conditional calc function