added sum function based on selected periods