Return value in cell based on other cells values combination in excel - excel

I have a table in Excel that has the following columns:
My table
dm: Can be 0 or 1
gdr: Can be 0 or 1
smk: Can be 0 or 1
agemin: min age number
agemax: max age number
sbpmin: min sbp number
sbpmax: max sbp number
chlmin: min chl number
chlmax: max chl number
The table is big with all possible combinations.
What i need is a way to find the value in result based on the input of:
dm, gd, smk, age, sbp and chl. As i mention the first 3 can be a 0 or a 1 but the other 3 is a number that must be contain in the range given by the columns min and max.
Has anyone have a clue on how can i solve this?
Thanks,

Using the provided table and assuming the parameters for a lookup are in column M (as shown in the below picture), then the formula in cell M9 and copied right to get the result is:
=IFERROR(INDEX($J$2:$J$4,MATCH(1,INDEX((M2=$A$2:$A$4)*(M3=$B$2:$B$4)*(M4=$C$2:$C$4)*(M5>=$D$2:$D$4)*(M5<=$E$2:$E$4)*(M6>=$F$2:$F$4)*(M6<=$G$2:$G$4)*(M7>=$H$2:$H$4)*(M7<=$I$2:$I$4),),0)),"No matches found")

Related

Presenting a value based on number or text in cell

I have a list of 4 values in Sheet1 and 4 values in Sheet2.
In Sheet3 I will combine a random selection of these numbers and return the value in a column. (edit: no random selection from Excel, its a part picked from a bucket)
(A fifth column in Sheet3 will be used to do calculations with ValueS1 and ValueS2)
Sheet1
NumberS1
ValueS1
1
17.10
2
17.20
3
17.12
4
17.15
Sheet2
NumberS2
ValueS2
1
16.10
2
16.20
3
16.12
4
16.15
Sheet3
NumberS1
NumberS2
ValueS1
ValueS2
1
3
17.10
16.12
2
2
17.20
16.20
4
1
17.15
16.10
3
4
17.12
16.15
What kind of function can give the desired return?
I have looked into examples using "Indirect" but cannot see how they will solve my problem.
for the randomization: =ROUNDUP(RAND()*4,0)
rand() gives you a number between 0 and 1, so rand()*4 gives you a number between 0 and 4.
roundup(x,y) round up the number x with y digits you want to round the number up to (in our case 0).
for import the right number from sheet 1 or 2: =VLOOKUP(A1,Sheet1!A1:B2,2,0)
A1 - The value you look for in sheet 1 or 2.
Sheet1!A1:B4 - The array he look for your value on the firs column, always on the first column.
2 - The column you want to import the value from. (because we write an array of tow columns. we can write here only 1 or 2)
0 - it's an Optionally index (0 or 1). o is if you want an exact match of the return value.
Regular Lookup could do:
=LOOKUP(A2:A5,Sheet1!A2:A5,Sheet1!B2:B5) in Sheet3!C2
And
=LOOKUP(B2:B5,Sheet2!A2:A5,Sheet2!B2:B5) in Sheet3!D2
Note that LOOKUP will give the result to the closest match smaller than the search value.
Or VLOOKUP:
=VLOOKUP(A2:A5,Sheet1!A2:B5,2,0) / =VLOOKUP(B2:B5,Sheet2!A2:B5,2,0)
VLOOKUP will error if the value is not found (the way used above). It uses arguments like this:
=VLOOKUP(What you want to look up, where you want to look for it, the column number in the range containing the value to return, return an Approximate or Exact match – indicated as 1/TRUE, or 0/FALSE)
Office 365 has XLOOKUP which combines the logic of the two above and some more:
=XLOOKUP(A2:A5,Sheet1!A2:A5,Sheet1!B2:B5,"value not found",0)
XLOOKUP uses the following arguments:
=XLOOKUP(lookup_value, lookup_array, return_array, [if_not_found], [match_mode], [search_mode])

Excel - assign values based on the first unique item

I have got an excel question that I can not answer. Here is my table:
ID Key Count Unique Available Text Results
1 0 Text-1 Dupe-Y
2 1 Y Text-1 Y
3 0 Text-1 Dupe-Y
4 0 Text-1 Dupe-Y
5 1 N Text-2 N
6 1 Y Text-3 Y
7 0 Text-2 Dupe-N
8 0 Duplicate Text-2 Dupe-N
9 0 Duplicate Text-2 Dupe-N
10 0 Y Text-2 Dupe-N
Id Key is just unique key.
Count unique picks up the first time each value in column Text appears. Available can have Y, N, Duplicate and Text is the main column I need to analyze my table. The Results are for the first time each value in Text appears (Count unique = 1), if there is a value in Available then that is the value I need, if Count Unique is 0 then is either Dupe-Y or Dupe-N depending on the value in Available.
I tried with a formula like this one but got stuck after initial progress. =IF(B2=0,"",IFERROR(IF(COUNTIF(D:D,D2)>1,IF(COUNTIF($D:$D,D2)=1,"",C2),1),1))
Note that the column Results is the one I need to populate with a formula that is not affected by sorting or lack of it.
I guess you got all those values and you just need a formula for column Results.
My formul will work only if the data is sorted like in your example. If sorting changes, formula will fail:
My formula is:
=IF(B2=1;D2;"Dupe-"&RIGHT(G1;1))

Sum of the greatest value in one column, plus the sum of the other values in another column

Consider the following sheet/table:
A B
1 90 71
2 40 25
3 60 16
4 110 13
5 87 82
I want to have a general formula in cell C1 that sums the greatest value in column A (which is 110), plus the sum of the other values in column B (which are 71, 25, 16 and 82). I would appreciate if the formula wasn't an array formula (as in requiring Ctrl + Shift + Enter). I don’t have Office 365, I have Excel 2019.
My attempt
Getting the greatest value in column A is easy, we use MAX(A1:A5).
So the formula I want in cell C1 should be something like:
=MAX(A1:A5) + SUM(array_of_values_to_be_summed)
Obtaining the values of the other rows in column B (what I called array_of_values_to_be_summed in the previous formula) is the hard part. I've read about using INDEX, MATCH, their combination, and obtaining arrays by using parenthesis and equal signs, and I've tried that, without success so far.
For example, I noticed that NOT((A1:A5 = MAX(A1:A5))) yields an array/list containing ones (or TRUEs) for the relative position of the rows to be summed, and containing a zero (or FALSE) for the relative position of the row to be omitted. Maybe this is useful, I couldn't find how.
Any ideas? Thanks.
Edit 1 (solution)
I managed to obtain what I wanted. I simply multiplied the array obtained with the NOT formula, by the range B1:B5. The final formula is:
=MAX(A1:A5) + SUM(NOT((A1:A5 = MAX(A1:A5))) * B1:B5)
Edit 2 (duplicate values)
I forgot to explain what the formula should do if there are duplicates in column A. In that case, the first term of my final formula (the term that has the MAX function) would be the one whose corresponding value in column B is smallest, and the value in column B of the other duplicates would be used in the second term (the one containing the SUM function).
For example, consider the following sheet/table:
A B
1 90 71
2 110 25
3 60 16
4 110 13
5 110 82
Based on the above table, the formula should yield 110 + (71 + 25 + 16 + 82) = 304.
Just to give context, the reason I want such a formula is because I’m writing a spreadsheet that automatically calculates the electric current rating of the short-circuit protective device of the feeder of a group of electric motors in a house or building or mall, as required by the article 430.62(A) of the US National Electrical Code. Column A is the current rating of the short-circuit protective device of the branch-circuit of each motors, and column B is the full-load current of each motor.
You can use this formula
=MAX(A1:A5)
+SUM(B1:B5)
-AGGREGATE(15,6,(B1:B5)/(A1:A5=MAX(A1:A5)),1)
Based on #Anupam Chand's hint for max-value-duplicates there could also be min-value-duplicates in column B for corresponding max-value-duplicates in column A. :) This formula would account for that
=SUM(B1:B5)
+(MAX(A1:A5)-AGGREGATE(15,6,(B1:B5)/(A1:A5=MAX(A1:A5)),1))
*SUMPRODUCT((A1:A5=MAX(A1:A5))*(B1:B5=AGGREGATE(15,6,(B1:B5)/(A1:A5=MAX(A1:A5)),1)))
Or with #Anupam Chand's shorter and better readable and overall better style :)
=SUM(B1:B5)
+(MAX(A1:A5)-MINIFS(B1:B5,A1:A5,MAX(A1:A5)))
*COUNTIFS(A1:A5,MAX(A1:A5),B1:B5,MINIFS(B1:B5,A1:A5,MAX(A1:A5)))
The explanation works for bot solutions:
The SUM-part just sums the whole list.
The second line gets the max-value for column A and the corresponding min-value of column B for the max-values in column A and adds or subtracts it respectively.
The third line counts, how many times the corresponding min-value for the max-value occurs and multiplies it with the second line.
Can you try this ?
=MAX(A1:A5)+SUM(B1:B5)-MINIFS(B1:B5,A1:A5,MAX(A1:A5))
What we're doing is adding the max of A to all rows of B and then subtracting the min value of B where A is the max.
If you have Excel 365 you can use the following LET-Formula
=LET(A,A1:A5,
B,B1:B5,
MaxA,MAX(A),
MinBExclude, MINIFS(B,A,MaxA),
sumB1,SUMPRODUCT(B*(A=MaxA)*(B<>MinBExclude)),
sumB2,SUMPRODUCT(B*(A<>MaxA)),
MaxA +sumB1+sumB2
A and B are shortcuts for the two ranges
MaxA returns the max value for A (110)
MinBExclude filters the values of column B by the MaxA-value (25, 13, 82) and returns the min-value of the filtered result (13)
sumB1 returns the sum of the other MaxA values from column B (26 + 82)
sumB2 returns the sum of the values from B where value in A <> MaxA (71 + 60)
and finally the result is returned
If you don't have Excel 365 you can add helper columns for MaxA, MinBExclude, sumB1 and sumB2 and the final result

How to return a value from a range of values

I would appreciate it if someone can answer this.
Lets say I got multiple rows with three column with min, max and the return value . And I wanted to create a single formula to search the min and max value and then gave back a return value based on the row . Let me just show it :
Min Max Return
0.01 10 0
10.01 20 5
20.01 30 12
30.01 40 15
Input 7 <---- User input
Return 0 <---- This should be calculated based on the user input against the table
Input 33 <---- User input
Return 15 <---- This should be calculated based on the user input against the table
If you mean a SQL Query, here is the query that jsut do the job for you :
SELECT Return from TABLE_Name
WHERE
Input >= Min AND Input < Max
Ok, I'll attempt another try:
=SUMPRODUCT(C2:C5*(F1>=A2:A5)*(F1<=B2:B5))
C2:C5 are the results, A2:A5 the minmum values, B2:B5 the maximum values and F1 the actual value.
Basically, SUMPRODUCT can be used as it does the calculation for every row and sums up the results. If the test succeeds, 1 is returned, otherwise 0. Thus, only the successful test will have a 1, all others will multiply their result with 0.
If I understood the question correctly, some nested IFs would do like (assuming input in A4 and the ranges like in the table):
=IF(AND(A4>B1,A4<B2),B3,IF(AND(A4>C1,A4<C2),C3,...
For more complex (meaning longer) tables you could also use a "helper" column (Column D):
IF(AND($A$4>B1,$A$4<B2),B3,"")
"drag" this down to copy it and then sum the column to get the result.
All a bit of a mess, but I can't think of any more elegant solution using excel formulas.

Excel - Finding Max value in a column

I have an Summary sheet set up data set up as follows-
Cat A Cat B Cat C Cat D
Name 1 0 0 0 0
Name 2 2 3 2 2
Name 3 2 2 2 2
Name 4 3 2 2 3
Name 5 2 3 2 3
I also then have separate tabs for each of Name1 through to Name 5.
The summary sheet contains the maximum values for each category from each tab. So the Cell at Cat A Name 1 should show the maximum value on Sheet(Name1) in the Cat A column.
So far so good. However each tab may not contain the same categories, so therefore I would like teh summary sheet to check the maximum value in each column by doing a search on the Cat name.
So far I have this-
=MATCH(Overview!S$1,Name1!$C$1:$V$1,0)
Which returns the column number with the right Category, in this case 13. So I can find the right column. What I am struggling with is to now find the maximum value in the column.
Can anyone help?
Thanks
IAssuming your search range goes to row 1000:
=MAX(INDEX(Name1!$C$2:$V$1000,0,MATCH(Overview!S$1,Name1!$C$1:$V$1,0)))
The 0 Row argument in Index means to select the entire column.
The Offset function is your key here.
After you've got the value from the match, you can pass it to the offset to get the correct column.
So, for example, you probably want something like:
=Max(Name1!$C1:$C2000)
But you don't know whether you should use the C column or the D column or whatever, in this case, it was 13, so is that the P column? (c=3, the match was 13 so 3+13 = 16 = P?), so I think you want something like this:
=Max(Offset(Name1!$C$1:$C$2000, 0, [result of your match expression] - 1))
Here's an example of what I think you want in GoogleDocs:
https://docs.google.com/spreadsheet/ccc?key=0Ai45AJPc2AWMdGRlZXNIdlZBaHJxc01qVlJWa1N1WXc

Resources