Match duplicates with highest numbers [excel formula]? - excel

Can someone help me with the formula here? I have used something like this before ={MAX(IF(...} but it doesn't really fit what I'm doing now.
=MAX(IF(Sheet1!$A$a:$A$1500=Sheet3!D19,Sheet1!$G$1:$G$1500))
I need to identify that I have duplicates in column A, then look at column B and find the highest value for e.g. cat, then match this highest value with the highest in column C (as you can see "cat" has two 140 figures but in C one of them =56, thus I need "OK" next to it). I would be greatly obliged for your help.
Col A B C Formula?
cat 140 56 OK
cat 140 54 x
cat 87 41 x
cat 91 13 x
cat 100 11 x
dog 230 12 x
dog 230 55 OK
dog 230 45 x
mouse 111 12 x
mouse 123 43 x
mouse 145 55 OK
mouse 103 54 x

Try this in C2 and fill down.
=IF(AND(B2=AGGREGATE(14, 7, B:B/(A$1:A$13=A2), 1), C2=AGGREGATE(14, 7, C:C/((A$1:A$13=A2)*(B$1:B$13=AGGREGATE(14, 7, B:B/(A$1:A$13=A2), 1))), 1)), "OK", "x")

Related

Check each value in a dataframe and if that is less means then change the value which is given

cateory Percentage
AB 99
CD 65
EF 12
GH 25
IJ 90
KL 100
If CD's percentage is less than 70 then change that as 71 else existing value is fine
If EF's percentage is less than 20 then change that as 21 else existing value is fine
If GH's percentage is less than 30 then change that as 45 else existing value is fine
For AB existing value is fine
Output
cateory Percentage
AB 99
CD 65
EF 21
GH 45
IJ 90
KL 100
Create list of tuples for replacement by compare both columns and if match replace by new value - last value of tuple:
L = [('CD', 70, 71), ('EF', 20, 21), ('GH', 30, 45)]
for cat, less, new in L:
m = df['cateory'].eq(cat) & df['Percentage'].lt(less)
df.loc[m, 'Percentage'] = new
print (df)
cateory Percentage
0 AB 99
1 CD 71
2 EF 21
3 GH 45
4 IJ 90
5 KL 100

IF formula too long

I’m trying to create a formula that will display mileage from one place to another.
Example: column one is location combinations (there are 39 locations and multiple combinations)
Eg-sams to Petes, sams to mc d, mc d to sams etc.
Last column with formula would automatically place mileage from point a to point b. Etc
The formula i created was IF but way too long
=IF(B12="SVES TO KHS",11,
IF(B12="SVES TO FRHS",4.1,
IF(B12="SVES TO CHS",6.9,
IF(B12="SVES TO KMS",9.5,
IF(B12="SVES TO ISM",6.2,
IF(B12="SVES TO HM",5.3,
IF(B12="SVES TO FHM",2.4,
IF(B12="SVES TO TSM",7.6,...
Is there a way to shorten the formula?
Best thing to do is create a separate table on sheet 2, in column a have a list of answers "SVES TO ", column b the miles. Then use a vlookup to find the miles
=Vlookup (b12, sheet 2!'a1:b50,2,0)
In this example there are 50 different SVES TO examples, change it to however many you have.
An X-to-Y/Y-to-X distance matrix should be your best bet. While VLOOKUP is good for a one-column-lookup/one-column-retrieval, an INDEX/MATCH/MATCH would be more appropriate for a true matrix.
Assume the folowwing data matrix with destinations along the first row and the first column.
a b c d e f g
a - 40 80 17 37 16 70
b 40 - 48 95 85 8 60
c 80 48 - 24 26 75 73
d 17 95 24 - 14 9 56
e 37 85 26 14 - 91 7
f 16 8 75 9 91 - 78
g 70 60 73 56 7 78 -
Note that distances like c-to-f are the same as f-to-c. (yes, there i a simple formula for this but that is another question). Obviously, any x-to-x or y-to-y should be zero when x = y.
In the sample image below your formula in L2 should be,
=INDEX($B$2:$H$8, MATCH(J2, A$2:A$8, 0), MATCH(K2, B$1:H$1, 0))
The cell and row highlighting were added with a couple simple conditional formats formulas.

How to generate random numbers from different intervals that add up to a fixed sum in excel?

I need to generate 13 numbers from 13 different intervals which will add up to 1360. In the chart below, "index" means the index of the 13 different numbers. Mean means the mean (average) of the intervals. The range will be plus or minus 15% of the mean as shown below. I will prefer to have the random numbers generated based on the normal distribution with N(mean, 7.5% of mean). I take it back. No normal distribution. Please use +- 15% as hard limits of the intervals.
It will be great if anyone could figure out how to do it in excel. Algorithms will be appreciated as well.
Index mean 15% low high
A 288 43 245 331
B 50 8 43 58
C 338 51 287 389
D 50 8 43 58
E 16 2 14 18
F 66 10 56 76
G 118 18 100 136
H 17 3 14 20
I 91 14 77 105
J 26 4 22 30
K 117 18 99 135
L 165 25 140 190
M 18 3 15 21
I would sort the table by increasing mean:
and use a column for a helper value (column H above).
The idea is to maintain -- while going to the next row -- the current deviation from a perfect aim for the final target. Perfect would mean that every random value coincides with the mean for that row. If a value is 2 less than the mean, then that 2 will appear in the H column for the next row. The random number generated for that next row will then not aim for the given mean, but for 2 less than the mean. The range for the random number will appropriately be reduced so that the low/high values will never be crossed.
By first sorting the rows, we can be sure that this corrected mean will always fall within the next row's low/high range, and so it will always be possible to generate an acceptable random number there.
The final value will be calculated differently: it will be the remainder that is needed to achieve the target sum. For the same reason as above, this value is guaranteed to be within the low/high range.
The formulas used are as follows:
| F | H
--+--------------------------------------------------+------------------------------
2 | =RANDBETWEEN(D2, E2) |
3 | =RANDBETWEEN(B3+H3-C3+ABS(H3), B3+H3+C3-ABS(H3)) | =SUM($B$2:$B2)-SUM($F$2:$F2)
4 | (copy above formula) | (copy above formula)
...| ... | ...
13 | (copy above formula) | (copy above formula)
14 | =SUM($B$2:$B14)-SUM($F$2:$F13) |
In theory the rows do not need to be sorted first, but then the formulas cannot be copied down like above, but must reference the correct rows. That would make it quite complicated.
If it is absolutely necessary that the rows are presented in order of the Index column (A, B, C...), then use another sheet to do the above. Then in the main sheet read the value into the F column with a VLOOKUP from the other sheet. So in F2 you would have:
=VLOOKUP(A2, OtherSheet!$A$2:$F$14, 6, 0)
Get the random number like this
num = Int ((300 - 200 + 1) * Rnd + 200) //between 200 and 300
Click here for more information
and the random number need to be the total sum minus the sum that you already got and the last one will be that left.
for example: (if we have 4 numbers sum up to 100)
A is a random number between 0 to 100 //lets say 42
then B is a random number between 0 to (100-42) => 0 to 78 //lets say 18
then C is a random number between 0 to (100-42-18) => 0 to 40 //lets say 25
then, in the end D is 100-42-18-25 => D is 15
*100-42-18-25 is the same as 100-Sum(A,B,C)
Here is my example generate random number based on low and high.
The formula in column F is just a RANDBETWEEN:
=RANDBETWEEN($D2,$E2)
Then you can get the result always equal to 1360 with the formula below for column G:
=F2/SUM($F$2:$F$14)*1360
So cell G15 will always be 1360 which is the sum of all those 13 intervals.

PowerPivot field of same Row in Calculation

Im trying to have a formula, that gets the first result of entry, for every line.
An Example Table would be like this:
Column A Column B Column C Excepted Output from Formula
3 99 P 18 P 4
4 88 P 144 P 1
2 77 P 2
2 77 P 2
1 88 P 1 P 1
1 99 P 4 P 4
2 44 P 5
3 22 P 7
1 88 P 99 P 1
Now, on Column D it should always show the first time it finds Coulmn A = 1, and Column B the same value as the own row (99 for the first row, 88 for the second, 77 for the 3rd...), and Display the Column C of it.
I tried it with the following Formula:
=CALCULATE(
FIRSTNONBLANK('Table'[Column C]; TRUE());
FILTER('Table';'Table'[Column A]=1);
FILTER('Table';'Table'[Column B]='Table'[Column B])
)
Which doesnt work. No errors, but it ignores the second filter.
If i now replace the "='Table'[Column B]" with a number that it should take (99,88,77...) it shows the correct result. But since its now a static number, it shows the same Result in every line, instead of calc it always new.
Can someone help?
Try this:
= CALCULATE(FIRSTNONBLANK('Table'[Column C], TRUE()),
FILTER(FILTER('Table','Table'[Column A]=1),'Table'[Column B] = earlier('Table'[Column B])))

Latest Value from the column level to specific code

Can anyone pls help me to get the latest/running value for A & B....
NAME FSales ESales
A 100 500
A 50 170
B 100 300
B 130 200
A 70 230
B 50 450
OUTPUT SHOULD BE
Output FSales ESales
A 70 230
B 50 450
As given in the image below, enter the formula in cell B12 and drag to right and then down.
=LOOKUP(2,1/($A$2:$A$7=$A12),B$2:B$7)

Resources