Solving the fundamental and optical gap problems, which yield information about charged and neutral excitations in electronic systems, is one of the biggest challenge in density-functional theory (DFT). Despite their intrinsic difference, we show that the two problems can be made formally identical by introducing a universal and canonical ensemble weight dependent exchange-correlation (xc) density functional. The weight dependence of the xc energy turns out to be the key ingredient for describing the infamous derivative discontinuity and represents a new path for its approximation.