but as you will see it creates a number of intermediate expressions, so it is not the best approach
Is the time to build the problem a bottleneck in your problem? If not, write the model that is the most readable to you. Only try improving performance if it the limiting factor.
Is there any reason not to write it just as:
model = Model()
@variable(model, p[1:4, 1:10] >= 0)
@expression(model, ex1[i=1:4, j=1:10], sum(p[i, t] for t in j:10))
@constraint(
model,
[j=1:10],
sum(rate[i] * ex1[i, j] + p[i, j] for i in 1:4) <= pd[j] + id[j],
)
In general, I wouldn’t expect the performance to be too different between the two approaches.