dimanche 6 novembre 2022

Excel Random Values with 2 Constraints

I've been attempting to build a matrix in Excel with random values. However, these random values must follow two constraints, which are a limit in the column total and another in the line total.

Take this matrix as an example:

Column A Total = 180 Column B Total = 200 Column C Total = 185 Line Total
Random 1 Random 2 Random 3 250
Random 4 Random 5 Random 6 125
Random 7 Random 8 Random 9 60

I can build a formula that allows the columns or the lines to have random values and add to the required total, however I can't arrive to a formula that combines both constraints.

I used this link to define the formula that always adds to the required total.

To allow for a better explanation, see the example of the table above, where the random numbers are now replaced with actual numbers:

Column A Total = 180 Column B Total = 200 Column C Total = 185 Line Total
200 20 30 250
10 80 35 125
5 30 25 60

As you can see, the total in the lines are correct, however the totals of the first column are incorrect and add up to more than what is allowed (215 > 180).

Note that the line values must add up to the total, however the columns must be less or equal, here are the conditions to clarify:

Line Totals
Line1: SUM(Random1, Random2, Random3) = 250
Line2: SUM(Random4, Random5, Random6) = 125
Line3: SUM(Random7, Random8, Random9) = 60

Column Totals
Column1: SUM(Random1, Random4, Random7) <= 180
Column2: SUM(Random2, Random5, Random8) <= 200
Column3: SUM(Random3, Random6, Random9) <= 185

The objective is to achieve it in Excel. Is this possible using formulas only? Or is this an optimization problem for which solver is required?




Aucun commentaire:

Enregistrer un commentaire