SELECT calc_status ,flag ,sum(fb_val_loc * r_rate) filter (WHERE version = 'ACTUALS' AND calc_status = 'CLOSED' AND flag = 'REMAINDER' AND fb_qty < 0) overship ,sum(fb_val_loc * r_rate) filter (WHERE version = 'ACTUALS' AND calc_status = 'CLOSED' AND flag = 'REMAINDER' AND fb_qty > 0) undership ,sum(fb_val_loc * r_rate) filter (WHERE version = 'ACTUALS' AND fb_qty = 0) no_units ,sum(fb_val_loc * r_rate) filter (WHERE version = 'ACTUALS' AND dhincr = 'C') credits ,sum(fb_val_loc * r_rate) filter (WHERE version = 'ACTUALS' AND "ddord#" = 0 ) no_units FROM rlarp.osmf_dev WHERE ( ( oseas = 2021 AND odate <@ daterange('2020-06-01','2021-04-11') ) OR sseas = 2021 ) AND fs_line = '41010' --AND version = 'ACTUALS' --AND calc_status = 'CLOSED' --AND flag = 'REMAINDER' GROUP BY calc_status, flag;