Function MyBins(MyValue As Single) As String Application.Volatile If SGPValue > 1 Then MyBins = "> 100%" ElseIf MyValue <= 1 And MyValue > 0.8 Then MyBins = "100%-80%" ElseIf MyValue <= 0.8 And MyValue > 0.65 Then MyBins = "80%-65%" ElseIf MyValue <= 0.65 And MyValue > 0.5 Then MyBins = "65%-50%" ElseIf MyValue <= 0.5 And MyValue > 0.2 Then MyBins = "50%-20%" ElseIf MyValue <= 0.2 And MyValue >= 0 Then MyBins = "20%-0%" ElseIf MyValue < 0 Then MyBins = "< 0" Else MyBins = "Please Verify" End If End Function
Without?
Would you use IF for that purpose? And when there are several bins you will have plenty of nested IFs?
The answer is to use LOOKUP. cf.: http://www.mrexcel.com/forum/excel-questions/631008-excel-formula-sort-into-bins.html#post3130377 In this example you can also see how an array, a table, can be encoded in a formula.
I think it is very neat to use ListObject Table to keep the parameters in, then the formula would look like:
=LOOKUP(B3;Table1[a];Table1[b]) where [a] is a column with upper limits and [b] contains the corresponding names of the bins.
Table 1
a b
-99999 < 1
1 1 to 1,9999
2 2 to 4,9999
5 5 to 9,9999
10 10 and avobe
To count bins to generate a histogram it is probably best to use countifs:
http://exceluser.com/formulas/countifs-frequency-distributions.htm
Brak komentarzy:
Prześlij komentarz