How can I return a minimum value in excel work sheet if the cells containing the values I am comparing , the values were created by a function - excel

Am trying to return the minimum value of cells excluding zero but when ever I do it using this function, it returns a zero not the minimum
Function:{=MIN(IF(DW2:EE2 = 0,"",DW2:EE2))}
The values in the cells are created by a function which is:
=IF(BJ2="",0,IF(BJ2="D1","1",IF(BJ2="D2","2",IF(BJ2="C3","3",IF(BJ2="C4","4",IF(BJ2="C5","5",IF(BJ2="C6","6",IF(BJ2="P7","7",IF(BJ2="P8","8",IF(BJ2>="F9","9"))))))))))
enter image description here

This answer is wrong, but it might give you an idea.
=IF(MIN(A1:A5)=0,SMALL(A1:A5,2),MIN(A1:A5))
This means the following (I'm always working from a list of values in the cells "A1" till "A5"):
Verify the minimum of the list.
2.1. If the minimum equals zero, then
take the second smallest value.
2.2. If the minimum does not equal zero,
then take that minimum.
However, there is one problem with the implementation of that approach: I expected =Small(range,2) to give the second smallest number of a list, which it does, but it does not, let me show you:
Range : 0, 1, 2, 3, 4, 5 => Small(Range,2) = 1 => OK
Range : 0, 1, 2, 3, 4, 0 => Small(Range,2) = 0 => NOK
Apparently, Small(,2) just orders the range, and takes the second element, regardless of the fact that it might be equal to Small(,1).
Does anybody know a solution or workaround for this issue?

Related

Excel : Find numbers in a list which when summed total a target number

Ive got a list of several thousand numbers.
I have a target number which is a sum of some of the list of numbers.
I want to be able to find what numbers in the list, when summed total to the target number.
Eg.
List :
1, 2, 3, 4, 5, 6, 7, 8
Target :
5
Result :
The target could be made from the sum of 1+4, 2+3, 5
If there are is no way the target can be achieved from the numbers in the list eg. list : 10,20 and the Target : 5 then the formula should output "no available matches"
That is a very simple example but in practice there are thousands of numbers in the list and some of the numbers are up to seven digits long.
Is there a formula could be used in excel (or google sheets) that would work this out automatically ? Preferably as a native function rather than VBA / Script.
You request is so complex that there is not a native function, which can do that. In top of it, the result of your function is a whole collection of possibilities (like [5, 1+4, 2+3] in your particular case), while Excel functions only generate a single result, which can be placed in a single cell.
In top of this, it's quite a difficult task to program, let me explain you why with some simple examples:
List : 1,2,3,4,5
Desired result: 36
=> no way: even when you sum all elements of the list, the result is not large enough.
List : 6,7,8,9,10
Desired result: 5
=> no way: even the smallest element in the list is larger than the result.
List : 1,2,20,21,23
Desired result: 10
=> no way (but how to make a computer see this?)
List : 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
Desired result: 119
=> easy as hell: the sum of all numbers of the list is 120, just subtract 1.
List: 2,4,6,8,10,12,14,16,18,20
Desired result: 11
=> no way: all numbers in the list are odd, you can't obtain an odd number.
As you see, for a human this is fairly simple, but how to get a computer to do this?

A cell is equal to Multiple numbers present in an IF statement, excel

I have a cell, and in this cell I can cycle through 1 to 15. I need another cell to check if that cell has any of these numbers: 1,3,5,7,9,11,13, and 15. If true, it outputs a 1. I couldn’t find nay examples for my specific problem, and I don’t really understand, so I need some help.
I have looked it up, but couldn’t understand it, and they don’t have g specific problem
=IF(B13=(1,3,5,7,9,11,13,15),1) this won’t work, but I imagine it to be something like this
Since they are all the ODD numbers:
=IF(ISODD(B13),1,0)
If you want specific numbers:
=IF(OR(B13={2,4,6,7}),1,0)
If 1 and 0 are your desired outputs we can remove the IF:
=--OR(B13={2,4,6,7})
Checks if the number is odd (based on the numbers you provided) and is below or equal to 15.
=IF(AND(ISODD(B13),B13<=15),1,0)
Or you could put the numbers you are checking for in a Select Case statement:
Sub CheckCell()
Dim ckNum As Integer
ckNum = Range("E25").Value
Select Case ckNum
Case 1, 3, 5, 7, 9, 11, 13, 15
Range("F25").Value = 1
Case Else
Range("F25").Value = 0
End Select
End Sub
Then you can check for any numbers you want.

Aggregate function (small) returns zeros rather than the smallest values

I am using excel's aggregate (small) function to find the smallest value for each name that appears in a column. The issue is that the formula below simply returns 0s everywhere there is a value in B.
The formula I am using is
=IF($B2<>"", AGGREGATE(15,7, ($B:$B)*($A2=$A:$A)*($B2<>""), 1), "")
where B contains the data I want the smallest value from and A contains identifying strings.
I appreciate any help you can lend!
You want to divide by the criteria:
=IF($B2<>"", AGGREGATE(15,7, ($B:$B)/(($A2=$A:$A)*($B:$B<>"")), 1), "")
Whenever ($A2=$A:$A) or ($B2<>"") is FALSE it will return 0 and anything multiplied by 0 is 0 and as such the smallest value is 0.
By dividing by the criteria we throw an #DIV/0 error which the 7 in the AGGREGATE's second criterion forces the formula to ignore and as such we only get the smallest of what returns TRUE or 1 in both Boolean. 1*1=1.
But one more thing. AGGREGATE is an array type formula so limiting the to only the data will speed it up.
=IF($B2<>"", AGGREGATE(15,7, ($B$1:INDEX($B:$B,MATCH("zzz",$A:$A)))/(($A2=$A$1:INDEX($A:$A,MATCH("zzz",$A:$A)))*($B$1:INDEX($B:$B,MATCH("zzz",$A:$A))<>"")), 1), "")
As per your comment:
=IF($B2 = AGGREGATE(15,7, ($B:$B)/(($A2=$A:$A)*($B:$B<>"")), 1),AGGREGATE(15,7, ($B:$B)/(($A2=$A:$A)*($B:$B<>"")), 1), "")

Equation to find minimum difference between given date and array of dates

I am attempting to write an equation that compares a date to an array of other dates given the same ID and then returns the minimum value found between 0 and 42 or returns a zero if the criteria does not match.
My current equation can identify whether a date pair matches the above criteria and returns a 1 if there is a match and a 0 for no match.
=IF(E15<>"",IFERROR(--(AGGREGATE(15,7,(E15-$H$2:$H$8000)/(($C$1:$C$8000=C15)*(E15-$H$2:$H$8000>=0)),1)<43),0),0)
I need to modify this equation to return the actual difference between the dates rather than just a 1 or 0.
I have been playing around with an equation like this:
=IF(E3<>"", IFERROR(IF(--(AGGREGATE(15, 6, (E3-$H$2:$H$8000)/(--($C$2:$C$8000=C3)*--(E3-$H$2:$H$8000>=0)), 1)<43)=1, MIN(--($C$2:$C$8000=C3)*(E3-$H$2:$H$8000)), ""), 0), 0)
But it returns nothing but zeros.
Please find sample data and expected values below.
For what you want you only need to move the check for less than 43 into the Aggregate and return blanks instead of 0:
=IF(E15<>"",IFERROR(AGGREGATE(15,7,(E15-$H$2:$H$8000)/(($C$1:$C$8000=C15)*(E15-$H$2:$H$8000>=0)*(E15-$H$2:$H$8000<43)),1),""),"")

Unable to SUM from COUNTIF

I have produced a set of data using a countif as exampled below:
=COUNTIFS(Matrix!$C6:$EZ6,"1",Matrix!$C$5:$EZ$5,"Attainment",Matrix!$C$3:$EZ$3,AD$3)
What this is doing is looking at a students grades against a subject and calculating the count of that grade. I have 5 grades, *, 1, 2, 3, 4, so I have 5 sets of calculated columns for each subject. What I am now trying to do is a weighted sum using the results of these countif's. * = 0, 1=1,2=2 etc, however students can get more than 1 grade per subject so I need to average these.
Student X got two 2 grades for biology and one 3 grade, I need to do (2x2/2) + (1x3/3) = 2.3
I have tried
=SUM((F4*0)+(AG4*1/AG4)+(BH4*2/BH4)+(CI4*3/CI4)+(DJ4*4/DJ4))
However, I get a divide by zero error as not all cells hold a value above zero.
Is there a way to create a formula that says if the cell value is greater than zero then do the calculations, but if not ignore. I can't do a nested if. So, if the sum of AG4*1/AG4 results in a number then add this, but if it produces a zero, do not and move on and do the same for the next calculation. I can't do a nested if as more than one calculation may return a positive value.
Your weighting formula seems wrong. You wrote '(2x2/2) + (1x3/3) = 2.3'. However, (2x2/2) + (1x3/3) returns 3.
Shouldn't it be (2x2) + (1x3) / (2+1) = 2.3 ?
Try using the following formula:
=(F4*0)+(AG4*1)+(BH4*2)+(CI4*3)+(DJ4*4) / SUM(F4,AG4,BH4,CI4,DJ4)
You can use wrap it in an IFERROR function to avoid errors for students with no grades

Resources