Adding strings to numbers with different length - string

I want to have an object like this, matching both of them and putting the names in each ID, both objects have a different length so I tried set names but it didn't work.
Any suggestions?
First Object
+----+-------+--+
| ID | Test | |
+----+-------+--+
| 1 | C | |
| 1 | M | |
| 1 | C | |
| 1 | M | |
| 2 | C | |
| 2 | M | |
| 2 | C | |
| 2 | M | |
| 4 | C | |
| 4 | M | |
| 4 | C | |
| 4 | M | |
+----+-------+--+
Second Object
+-----------+-----+--+
| Names | ID | |
+-----------+-----+--+
| Pepsi | 1 | |
| Coke | 2 | |
| Acuarious | 3 | |
| Fanta | 4 | |
| Beer | 5 | |
| Fries | 6 | |
+-----------+-----+--+
+----+-------+--------+--+
| ID | Names | Test | |
+----+-------+--------+--+
| 1 | Pepsi | C | |
| 1 | Pepsi | M | |
| 1 | Pepsi | C | |
| 1 | Pepsi | M | |
| 2 | Coke | C | |
| 2 | Coke | M | |
| 2 | Coke | C | |
| 2 | Coke | M | |
| 4 | Fanta | C | |
| 4 | Fanta | M | |
| 4 | Fanta | C | |
| 4 | Fanta | M | |
+----+-------+--------+--+

I think I sorted it out.
a <- merge(firstobject,secondobject,by.x="ID",by.y="ID",all.x=T,all.y=T)
This create a file that match by ID and at the same time put NA for those ones that don´t match.
To get rid off the NAs
a <- a[!is.na(a$ID),]
I hope this helps.!!!

Related

An unconventional transpose in excel

A part of my file consists in this:
Et SF
1 4.4937
1 5.1257
1 5.2018
1 5.3755
1 5.741
1 5.9086
1 6.1399
1 6.2518
2 3.0424
2 3.2744
2 3.883
2 3.9595
2 3.9892
2 4.1603
2 4.2943
2 4.5118
And I would like to transpose this way:
Et SF SF SF SF SF SF SF SF
1 4.4937 5.1257 5.2018 5.3755 5.741 5.9086 6.1399 6.2518
2 3.0424 3.2744 3.883 3.9595 3.9892 4.1603 4.2943 4.5118
Is it possible to do this in excel. I tried the option OFFSET but I wasn't able to do this.
You did not mention what did you try. There are many ways:
| | A | B | | Copy | | 4.4937 | 5.1257 | 5.2018 | 5.3755 | 5.741 | 5.9086 | 6.1399 | 6.2518 |
|----|:-:|:------:|:-:|:------:|:------:|--------|-----------|--------|--------|--------|--------|--------|--------|
| 1 | 1 | 4.4937 | = | ===== | ==| | 3.0424 | 3.2744 | 3.883 | 3.9595 | 3.9892 | 4.1603 | 4.2943 | 4.5118 |
| 2 | 1 | 5.1257 | | | | | A | Transpose | | | | | | |
| 3 | 1 | 5.2018 | | | | | | | | | | | | | |
| 4 | 1 | 5.3755 | | | | | | | | | | | | | |
| 5 | 1 | 5.741 | | | | | | | | | | | | | |
| 6 | 1 | 5.9086 | | | | | | | | | | | | | |
| 7 | 1 | 6.1399 | | | | | | | | | | | | | |
| 8 | 1 | 6.2518 | | | V | | | | | | | | | |
| 9 | 2 | 3.0424 | > | 3.0424 | 4.4937 | ==| | | | | | | | |
| 10 | 2 | 3.2744 | > | 3.2744 | 5.1257 | | | | | | | | |
| 11 | 2 | 3.883 | > | 3.883 | 5.2018 | | | | | | | | |
| 12 | 2 | 3.9595 | > | 3.9595 | 5.3755 | | | | | | | | |
| 13 | 2 | 3.9892 | > | 3.9892 | 5.741 | | | | | | | | |
| 14 | 2 | 4.1603 | > | 4.1603 | 5.9086 | | | | | | | | |
| 15 | 2 | 4.2943 | > | 4.2943 | 6.1399 | | | | | | | | |
| 16 | 2 | 4.5118 | > | 4.5118 | 6.2518 | | | | | | | | |
Just copy the first section (1) at the right side of the second section (2). Copy the complete selection and paste transposed.
If you want to just make though a formula on the same sheet:
| | A | B | C | D | E | F | G | H | I | J | K | L | M |
|----|:--:|:------:|:-:|:-:|:---------------------------:|-----------------------------|-----------------------------|-----|---|---|---|---|---|
| 1 | Et | SF | | | | | | | | | | | |
| 2 | 1 | 4.4937 | | 1 | =INDIRECT("B" & COLUMN()-3) | =INDIRECT("B" & COLUMN()-3) | =INDIRECT("B" & COLUMN()-3) | ... | | | | | |
| 3 | 1 | 5.1257 | | 2 | =INDIRECT("B" & COLUMN()+5) | =INDIRECT("B" & COLUMN()+5) | =INDIRECT("B" & COLUMN()+5) | ... | | | | | |
| 4 | 1 | 5.2018 | | | | | | | | | | | |
| 5 | 1 | 5.3755 | | | | | | | | | | | |
| 6 | 1 | 5.741 | | | | | | | | | | | |
| 7 | 1 | 5.9086 | | | | | | | | | | | |
| 8 | 1 | 6.1399 | | | | | | | | | | | |
| 9 | 1 | 6.2518 | | | | | | | | | | | |
| 10 | 2 | 3.0424 | | | | | | | | | | | |
| 11 | 2 | 3.2744 | | | | | | | | | | | |
| 12 | 2 | 3.883 | | | | | | | | | | | |
| 13 | 2 | 3.9595 | | | | | | | | | | | |
| 14 | 2 | 3.9892 | | | | | | | | | | | |
| 15 | 2 | 4.1603 | | | | | | | | | | | |
| 16 | 2 | 4.2943 | | | | | | | | | | | |
| 17 | 2 | 4.5118 | | | | | | | | | | | |
Hope it helps!

SIGN() formula returns unexpected results

In continuation of my previous question: Sumproduct with multiple criteria on one range
Jeeped provided me with an very helpful formula to achieve a sumproduct() which takes multiple criteria. My current case is however a bit broader:
Take these example tables:
First column is the ID number, second column a respondent group(A,B). Column headers are question types (X,Y,Z).
Table Q1
| | | X | Y | Y | Z | Y |
|----|---|---|---|---|---|---|
| 1 | A | 2 | 2 | 1 | | 1 |
| 2 | A | 1 | 1 | | | 2 |
| 3 | A | 1 | 1 | | | 1 |
| 4 | A | 2 | 1 | | | 1 |
| 5 | A | 1 | 2 | 1 | | 1 |
| 6 | A | 1 | 1 | | | 1 |
| 7 | A | | | | | |
| 8 | A | | | | | |
| 9 | A | 1 | 1 | | | 1 |
| 10 | A | 2 | 2 | 2 | | 2 |
| 11 | A | | | | | |
| 12 | A | 1 | 2 | 1 | | 2 |
| 13 | B | | | | | |
| 14 | B | 1 | 1 | | | 1 |
| 15 | B | 2 | 2 | 1 | | 1 |
Table Q2
| | | X | Y | Y | Z | Y |
|----|---|---|---|---|---|---|
| 1 | A | 1 | 2 | 1 | | 1 |
| 2 | A | 1 | 1 | | | 1 |
| 3 | A | 1 | 1 | | | 1 |
| 4 | A | 1 | 1 | | | 1 |
| 5 | A | 1 | 1 | | | 1 |
| 6 | A | 1 | 1 | | | 1 |
| 7 | A | | | | | |
| 8 | A | | | | | |
| 9 | A | 1 | 1 | | | 1 |
| 10 | A | 1 | 1 | | | 1 |
| 11 | A | | | | | |
| 12 | A | 1 | 2 | 1 | | 1 |
| 13 | B | | | | | |
| 14 | B | 1 | 1 | | | 1 |
| 15 | B | 1 | 2 | 1 | | 1 |
Now I want to know the amount of times a respondent answered 1 (yes) on Q2 for each question type (X,Y,Z). The catch is that if someone answered 1 (yes) on Q1 it should "override" the answer on Q2, as we assume that when someone answers yes on Q1 (implementation of a measure), their answer on Q2 (knowledge of said measure) has to be yes as well.
The second catch is that for the first two occurrences of Y there can only be yes in one of both columns, so in fact there can only be two yes answers for question type Y for each respondent.
I used the following formula (on sheet 3): =SUMPRODUCT(SIGN(('Q1'!$C$2:$G$16=1)+('Q2'!$C$2:$G$16=1))*('Q2'!$B$2:$B$16=Blad3!$D5)*('Q2'!$C$1:$G$1=Blad3!E$4)) to obtain the following results.
| | X | Y | Z |
|---|---|----|---|
| A | 9 | 19 | 0 |
| B | 2 | 4 | 0 |
For X these results are correct, as there are 9 1's in table Q2.
For Y the results for B are correct, for A however they are not, as there are only 9 respondents, answering max 2 questions would result in a max of 18, we have 19 however.
It turns out there is nothing wrong with the formula, just that it isn't suited for the way this data is organised. If you look at row 5:
Q1
| | | X | Y | Y | Z | Y |
|----|---|---|---|---|---|---|
| 5 | A | 1 | 2 | 1 | | 1 |
Q2
| | | X | Y | Y | Z | Y |
|----|---|---|---|---|---|---|
| 5 | A | 1 | 1 | | | 1 |
If we condense that to everywhere there is a 1 in any of the Y column we get this table:
| | | X | Y | Y | Z | Y |
|----|---|---|---|---|---|---|
| 5 | A | | 1 | 1 | | 1 |
When I ask for the sumproduct() for this combined table the result will be 3.
To prevent this I added a helper column (between the two Y and the Z column) to my tables, with the following formula: IF(OR(D1=1,E1=1),1,""). Removed the headers from the double Y columns, and re-running the query produced the correct results.
New table Q1 looks like this then:
| | | X | | | Y | Z | Y |
|----|---|---|---|---|---|---|---|
| 1 | A | 2 | 2 | 1 | 1 | | 1 |
| 2 | A | 1 | 1 | | 1 | | 2 |
| 3 | A | 1 | 1 | | 1 | | 1 |
| 4 | A | 2 | 1 | | 1 | | 1 |
| 5 | A | 1 | 2 | 1 | 1 | | 1 |
| 6 | A | 1 | 1 | | 1 | | 1 |
| 7 | A | | | | | | |
| 8 | A | | | | | | |
| 9 | A | 1 | 1 | | 1 | | 1 |
| 10 | A | 2 | 2 | 2 | | | 2 |
| 11 | A | | | | | | |
| 12 | A | 1 | 2 | 1 | 1 | | 2 |
| 13 | B | | | | | | |
| 14 | B | 1 | 1 | | 1 | | 1 |
| 15 | B | 2 | 2 | 1 | 1 | | 1 |

Calculate where type clause from two different tables

I haven't written DAX in a while and I'm having a bit of a hard time putting this together and I am hoping someone could throw in a suggestion.
What I have:
Qty Table (a lot more months than January):
+----------+-----------+----------+
| Location | Date | LaborQty |
+----------+-----------+----------+
| NY | 1/3/2017 | 41.024 |
| NY | 1/4/2017 | 33.836 |
| NY | 1/5/2017 | 20.431 |
| NY | 1/6/2017 | 35.544 |
| NY | 1/7/2017 | 0 |
| NY | 1/9/2017 | 33.337 |
| NY | 1/10/2017 | 41.799 |
| NY | 1/11/2017 | 70.469 |
| NY | 1/12/2017 | 35.514 |
| NY | 1/13/2017 | 31.573 |
| NY | 1/15/2017 | 0 |
| NY | 1/16/2017 | 22.041 |
| NY | 1/17/2017 | 30.518 |
| NY | 1/18/2017 | 47.576 |
| NY | 1/19/2017 | 29.53 |
| NY | 1/20/2017 | 18.155 |
| NY | 1/21/2017 | 0 |
| NY | 1/23/2017 | 31.284 |
| NY | 1/24/2017 | 27.695 |
| NY | 1/25/2017 | 38.907 |
| NY | 1/26/2017 | 16.289 |
| NY | 1/27/2017 | 30.976 |
| NY | 1/28/2017 | 0 |
| NY | 1/30/2017 | 21.434 |
| NY | 1/31/2017 | 16.49 |
+----------+-----------+----------+...etc
Rates Table:
+----------+-----------+------------+-----------+---------+-----------+--------+
| Location | DateFrom | DateTo | MonthFrom | MonthTo | RateType | Amount |
+----------+-----------+------------+-----------+---------+-----------+--------+
| NY | 1/1/2017 | 6/30/2017 | 1 | 6 | LaborRate | 129.7 |
| NY | 7/1/2017 | 9/30/2017 | 7 | 9 | LaborRate | 129.8 |
| NY | 10/1/2017 | 12/31/2017 | 10 | 12 | LaborRate | 129.9 |
| DC | 1/1/2017 | 6/30/2017 | 1 | 6 | LaborRate | 130.1 |
| DC | 7/1/2017 | 9/30/2017 | 7 | 9 | LaborRate | 130.5 |
| DC | 10/1/2017 | 12/31/2017 | 10 | 12 | LaborRate | 130.7 |
+----------+-----------+------------+-----------+---------+-----------+--------+
Desired type of output for the month (e.g. LaborQty x LaborRate):
+-------+----------+-----------+------------+
| Month | LaborQty | LaborRate | Result |
+-------+----------+-----------+------------+
| 1 | 674.22 | 129.74 | 87473.3 |
| 2 | 350 | 129.74 | 45409 |
| 3 | 375 | 129.74 | 48652.5 |
| 4 | 400 | 129.74 | 51896 |
| 5 | 380 | 129.74 | 49301.2 |
| 6 | 500 | 129.74 | 64870 |
| 7 | 550 | 129.76 | 71368 |
| 8 | 600 | 129.76 | 77856 |
| 9 | 675 | 129.76 | 87588 |
| 10 | 700 | 129.98 | 90986 |
| 11 | 780 | 129.98 | 101384.4 |
+-------+----------+-----------+------------+
What I am trying to write:
A DAX measure that will output amount like the one shown in the result column. If I where to write a linq query for picking the correct rate it will look something like this:
LaborRate = db.Rates
.Where(a => a.DateFrom <= SelectedDate & a.DateTo >= SelectedDate & a.RateType == "LaborRate")
.Select(a => a.Amount).Sum();
I have tried a combination of CALCULATE, SUM, SUMX, FILTER, RELATED but I couldn't get it to work. Any advice would be much appreciated. What would be the simplest approach?
I was able to achieve this by doing the following.
Add Month = MONTH(Qty[Date]) as a calculated column to your Qty table.
Create a TotalLaborQty measure in the Qty table as SUM(Qty[LaborQty]).
Define a LaborRate measure in the Rates table as detailed below.
Define a Result measure as [TotalLaborQty] * [LaborRate].
Set them up in a matrix with Qty[Location] and Qty[Month] in the rows and the three measures as the values.
LaborRate =
VAR SelectedMonth = SELECTEDVALUE(Qty[Month])
VAR SelectedLocation = SELECTEDVALUE(Qty[Location])
RETURN CALCULATE(SUM(Rates[Amount]),
FILTER(ALL(Rates),
Rates[MonthFrom] <= SelectedMonth &&
Rates[MonthTo] >= SelectedMonth &&
Rates[Location] = SelectedLocation))

Blending Model: Oil Production

Oil Blending
An oil company produces three brands of oil: Regular, Multigrade, and
Supreme. Each brand of oil is composed of one or more of four crude stocks, each having a different lubrication index. The relevant data concerning the crude stocks are as follows.
+-------------+-------------------+------------------+--------------------------+
| Crude Stock | Lubrication Index | Cost (€/barrell) | Supply per day (barrels) |
+-------------+-------------------+------------------+--------------------------+
| 1 | 20 | 7,10 | 1000 |
+-------------+-------------------+------------------+--------------------------+
| 2 | 40 | 8,50 | 1100 |
+-------------+-------------------+------------------+--------------------------+
| 3 | 30 | 7,70 | 1200 |
+-------------+-------------------+------------------+--------------------------+
| 4 | 55 | 9,00 | 1100 |
+-------------+-------------------+------------------+--------------------------+
Each brand of oil must meet a minimum standard for a lubrication index, and each brand
thus sells at a different price. The relevant data concerning the three brands of oil are as
follows.
+------------+---------------------------+---------------+--------------+
| Brand | Minimum Lubrication index | Selling price | Daily demand |
+------------+---------------------------+---------------+--------------+
| Regular | 25 | 8,50 | 2000 |
+------------+---------------------------+---------------+--------------+
| Multigrade | 35 | 9,00 | 1500 |
+------------+---------------------------+---------------+--------------+
| Supreme | 50 | 10,00 | 750 |
+------------+---------------------------+---------------+--------------+
Determine an optimal output plan for a single day, assuming that production can be either
sold or else stored at negligible cost.
The daily demand figures are subject to alternative interpretations. Investigate the
following:
(a) The daily demands represent potential sales. In other words, the model should contain demand ceilings (upper limits). What is the optimal profit?
(b) The daily demands are strict obligations. In other words, the model should contain demand constraints that are met precisely. What is the optimal profit?
(c) The daily demands represent minimum sales commitments, but all output can be sold. In other words, the model should permit production to exceed the daily commitments. What is the optimal profit?
QUESTION
I've been able to construct the following model in Excel and solve it via OpenSolver, but I'm only able to integrate the mix for the Regular Oil.
I'm trying to work my way through the book Optimization Modeling with Spreadsheets by Kenneth R. Baker but I'm stuck with this exercise. While I could transfer the logic from another blending problem I'm not sure how to construct the model for multiple blendings at once.
I modeled the problem as a minimization problem on the cost of the different crude stocks. Using the Lubrication Index data I built the constraint for the R-Lub Index as a linear constraint. So far the answer seems to be right for the Regular Oil. However using this approach I've no idea how to include even the second Multigrade Oil.
+--------------------+--------+--------+--------+--------+--+-------------+----+------+
| Decision Variables | | | | | | | | |
+--------------------+--------+--------+--------+--------+--+-------------+----+------+
| | C1 | C2 | C3 | C4 | | | | |
+--------------------+--------+--------+--------+--------+--+-------------+----+------+
| Inputs | 1000 | 0 | 1000 | 0 | | | | |
+--------------------+--------+--------+--------+--------+--+-------------+----+------+
| | | | | | | | | |
+--------------------+--------+--------+--------+--------+--+-------------+----+------+
| Objective Function | | | | | | Total | | |
+--------------------+--------+--------+--------+--------+--+-------------+----+------+
| Cost | 7,10 € | 8,50 € | 7,70 € | 9,00 € | | 14.800,00 € | | |
+--------------------+--------+--------+--------+--------+--+-------------+----+------+
| | | | | | | | | |
+--------------------+--------+--------+--------+--------+--+-------------+----+------+
| Constraints | | | | | | LHS | | RHS |
+--------------------+--------+--------+--------+--------+--+-------------+----+------+
| C1 supply | 1 | | | | | 1000 | <= | 1000 |
+--------------------+--------+--------+--------+--------+--+-------------+----+------+
| C2 supply | | 1 | | | | 0 | <= | 1100 |
+--------------------+--------+--------+--------+--------+--+-------------+----+------+
| C3 supply | | | 1 | | | 1000 | <= | 1200 |
+--------------------+--------+--------+--------+--------+--+-------------+----+------+
| C4 supply | | | | 1 | | 0 | <= | 1100 |
+--------------------+--------+--------+--------+--------+--+-------------+----+------+
| R- Lub Index | -5 | 15 | 5 | 30 | | 0 | >= | 0 |
+--------------------+--------+--------+--------+--------+--+-------------+----+------+
| R- Output | 1 | 1 | 1 | 1 | | 2000 | = | 2000 |
+--------------------+--------+--------+--------+--------+--+-------------+----+------+
| | | | | | | | | |
+--------------------+--------+--------+--------+--------+--+-------------+----+------+
| Blending Data | | | | | | | | |
+--------------------+--------+--------+--------+--------+--+-------------+----+------+
| R- Lub | 20 | 40 | 30 | 55 | | 25 | >= | 25 |
+--------------------+--------+--------+--------+--------+--+-------------+----+------+
Here is the model with Excel formulars:
+--------------------+------+-----+------+----+--+----------------------------------------------------+----+------+
| Decision Variables | | | | | | | | |
+--------------------+------+-----+------+----+--+----------------------------------------------------+----+------+
| | C1 | C2 | C3 | C4 | | | | |
+--------------------+------+-----+------+----+--+----------------------------------------------------+----+------+
| Inputs | 1000 | 0 | 1000 | 0 | | | | |
+--------------------+------+-----+------+----+--+----------------------------------------------------+----+------+
| | | | | | | | | |
+--------------------+------+-----+------+----+--+----------------------------------------------------+----+------+
| Objective Function | | | | | | Total | | |
+--------------------+------+-----+------+----+--+----------------------------------------------------+----+------+
| Cost | 7,1 | 8,5 | 7,7 | 9 | | =SUMMENPRODUKT(B5:E5;B8:E8) | | |
+--------------------+------+-----+------+----+--+----------------------------------------------------+----+------+
| | | | | | | | | |
+--------------------+------+-----+------+----+--+----------------------------------------------------+----+------+
| Constraints | | | | | | LHS | | RHS |
+--------------------+------+-----+------+----+--+----------------------------------------------------+----+------+
| C1 supply | 1 | | | | | =SUMMENPRODUKT($B$5:$E$5;B11:E11) | <= | 1000 |
+--------------------+------+-----+------+----+--+----------------------------------------------------+----+------+
| C2 supply | | 1 | | | | =SUMMENPRODUKT($B$5:$E$5;B12:E12) | <= | 1100 |
+--------------------+------+-----+------+----+--+----------------------------------------------------+----+------+
| C3 supply | | | 1 | | | =SUMMENPRODUKT($B$5:$E$5;B13:E13) | <= | 1200 |
+--------------------+------+-----+------+----+--+----------------------------------------------------+----+------+
| C4 supply | | | | 1 | | =SUMMENPRODUKT($B$5:$E$5;B14:E14) | <= | 1100 |
+--------------------+------+-----+------+----+--+----------------------------------------------------+----+------+
| R- Lub Index | -5 | 15 | 5 | 30 | | =SUMMENPRODUKT($B$5:$E$5;B15:E15) | >= | 0 |
+--------------------+------+-----+------+----+--+----------------------------------------------------+----+------+
| R- Output | 1 | 1 | 1 | 1 | | =SUMMENPRODUKT($B$5:$E$5;B16:E16) | = | 2000 |
+--------------------+------+-----+------+----+--+----------------------------------------------------+----+------+
| | | | | | | | | |
+--------------------+------+-----+------+----+--+----------------------------------------------------+----+------+
| Blending Data | | | | | | | | |
+--------------------+------+-----+------+----+--+----------------------------------------------------+----+------+
| R- Lub | 20 | 40 | 30 | 55 | | =SUMMENPRODUKT($B$5:$E$5;B19:E19)/SUMME($B$5:$E$5) | >= | 25 |
+--------------------+------+-----+------+----+--+----------------------------------------------------+----+------+
A nudge in the right direction would be a tremendous help.
I think you want your objective to be Profit, which I would define as the sum of sales value - sum of cost.
To include all blends, develop calculations for Volume produced, Lube Index, Cost, and Value for each blend. Apply constraints for volume of stock used, volume produced, and lube index, and optimize for Profit.
I put together the model as follows ...
Columns A through D is the information you provided.
The 10's in G2:J5 are seed values for the stock volumes used in each blend. Solver will manipulate these.
Column K contains the total product volume produced. These will be constrained in different ways, as per your investigation (a), (b), and (c). It is =SUM(G3:J3) filled down.
Column L is the Lube Index for the product. As you noted, it is a linear blend - this is typically not true for blending problems. These values will be constrained in Solver. It is {=SUMPRODUCT(G3:J3,TRANSPOSE($B$2:$B$5))/$K3} filled down. Note that it is a Control-Shift-Enter (CSE) formula, required because of the TRANSPOSE.
Column M is the cost of the stock used to create the product. This is used in the Profit calculation. It is {=SUMPRODUCT(G3:J3,TRANSPOSE($C$2:$C$5))}, filled down. This is also a CSE formula.
Column N is the value of the product produced. This is used in the Profit calculation. It is =K3*C8 filled down.
Row 7 is the total stock volume used to generate all blends. These values will be constrained in Solver. It is =SUM(G3:G5), filled to the right.
The profit calculation is =SUM(N3:N5)-SUM(M3:M5).
Below is a snap of the Solver dialog box ...
It does the following ...
The objective is to maximize profit.
It will do this by manipulating the amount of stock that goes into each blend.
The first four constraints ($G$7 through $J$7) ensure the amount of stock available is not violated.
The next three constraints ($K$3 through $K$5) are for case (a) - make no more than product than there is demand.
The last three constraints ($L$3 through $L$5) make sure the lube index meets the minimum specification.
Not shown - I selected options for GRG Nonlinear and selected "Use Multistart" and deselected "Require Bounds on Variables".
Below is the result for case (a) ...
For case (b), change the constraints on Column K to be "=" instead of "<=". Below is the result ...
For case (c), change the constraints on Column K to be ">=". Below is the result ...
I think I came up with a solution, but I'm unsure if this is correct.
| Decision Variables | | | | | | | | | | | | | | | | |
|--------------------|---------|--------|--------|--------|-------------|--------|--------|--------|--------|--------|--------|--------|---|--------------------------------|----|------|
| | C1R | C1M | C1S | C2R | C2M | C2S | C3R | C3M | C3S | C4R | C4M | C4S | | | | |
| Inputs | 1000 | 0 | 0 | 800 | 0 | 300 | 0 | 1200 | 0 | 200 | 300 | 600 | | | | |
| | | | | | | | | | | | | | | | | |
| Objective Function | | | | | | | | | | | | | | Total Profit (Selling - Cost) | | |
| Cost | 7,10 € | 7,10 € | 7,10 € | 8,50 € | 8,50 € | 8,50 € | 7,70 € | 7,70 € | 7,70 € | 9,00 € | 9,00 € | 9,00 € | | 3.910,00 € | | |
| | | | | | | | | | | | | | | | | |
| Constraints | | | | | | | | | | | | | | LHS | | RHS |
| Regular | -5 | | | 15 | | | 5 | | | 30 | | | | 13000 | >= | 0 |
| Multi | | -15 | | | 5 | | | -5 | | | 20 | | | 0 | >= | 0 |
| Supreme | | | -30 | | | -10 | | | -20 | | | 5 | | 0 | >= | 0 |
| C1 Supply | 1 | 1 | 1 | | | | | | | | | | | 1000 | <= | 1000 |
| C2 Supply | | | | 1 | 1 | 1 | | | | | | | | 1100 | <= | 1100 |
| C3 Supply | | | | | | | 1 | 1 | 1 | | | | | 1200 | <= | 1200 |
| C4 Supply | | | | | | | | | | 1 | 1 | 1 | | 1100 | <= | 1100 |
| Regular Demand | 1 | | | 1 | | | 1 | | | 1 | | | | 2000 | >= | 2000 |
| Multi Demand | | 1 | | | 1 | | | 1 | | | 1 | | | 1500 | >= | 1500 |
| Supreme Demand | | | 1 | | | 1 | | | 1 | | | 1 | | 900 | >= | 750 |
| | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | |
| Selling | | | | | | | | | | | | | | | | |
| Regular | 8,50 € | x | 2000 | = | 17.000,00 € | | | | | | | | | | | |
| Multi | 9,00 € | x | 1500 | = | 13.500,00 € | | | | | | | | | | | |
| Supreme | 10,00 € | x | 900 | = | 9.000,00 € | | | | | | | | | | | |
| | | | | | 39.500,00 € | | | | | | | | | | | |

Expand a data set using two columns

In Excel, I have two columns of data that I wish to combine.
Current set of data:
+---------+---------+
| column1 | column2 |
+---------+---------+
| a | 1 |
| b | 2 |
| c | 3 |
| d | 4 |
| | 5 |
| | 6 |
| | 7 |
+---------+---------+
For each value in column1, I need to assign all of the values in column2 so it looks like this:
+---------+---------+
| column1 | column2 |
+---------+---------+
| a | 1 |
| a | 2 |
| a | 3 |
| a | 4 |
| a | 5 |
| a | 6 |
| a | 7 |
+---------+---------+
| b | 1 |
| b | 2 |
| b | 3 |
| b | 4 |
| b | 5 |
| b | 6 |
| b | 7 |
+---------+---------+
| c | 1 |
| c | 2 |
| c | 3 |
| c | 4 |
| c | 5 |
| c | 6 |
| c | 7 |
+---------+---------+
| d | 1 |
| d | 2 |
| d | 3 |
| d | 4 |
| d | 5 |
| d | 6 |
| d | 7 |
+---------+---------+
How can I do this?
Do I need to find a macro/VB solution?
Since seems unlikely to receive any other answer:
in A1: a
in B1: =MOD(ROW()-1,7)+1
in A2: =IF(MOD(ROW()-1,7)>0,CHAR(CODE(A1)),CHAR(CODE(A1)+1))
Copy both formulae down to suit.

Resources