This work introduces a new analytical approach to the formulation of optimization problems with piecewise-defined (PD) objective functions. First, we introduce a new definition of multivariate PD functions and derive formal results for their continuity and differentiability. Then, we obtain closed-form expressions for the calculation of their moments. We apply these findings to three classes of optimization problems involving coherent risk measures. The method enables one to obtain insights on problem structure and on sensitivity to imprecision at the problem formulation stage, eliminating reliance on ad-hoc post-optimality numerical calculations.