I have a set of data in Excel and in one column is a estimate (number of weeks)
I want an Excel formula to bucket it into
Another method to create this would be using the if
conditionals...meaning you would reference a cell that has a value and depending on that value it will give you the bucket such as small
.
For example, =if(b2>30,"large",if(b2>20,"medium",if(b2>=10,"small",if(b2<10,"tiny",""))))
So if cell b2
had a value of 12
, then it will return the word small
.
Hope this was what you're looking for.
I used the attached formula to categorize sales figures into/within intervals of a bin range as shown the formula is:
=IF(MOD(B5,$B$1)<>0,($B$1*(1+((B5-(MOD(B5,$B$1)))/$B$1))),($B$1*(1+((B5-(MOD(B5,$B$1)))/$B$1))-$B$1))
Here cells are as shown in example
I use this trick for equal data bucketing. Instead of text result you get the number. Here is example for four buckets. Suppose you have data in A1:A100
range. Put this formula in B1:
=MAX(ROUNDUP(PERCENTRANK($A$1:$A$100,A1) *4,0),1)
Fill down the formula all across B column and you are done. The formula divides the range into 4 equal buckets and it returns the bucket number which the cell A1 falls into. The first bucket contains the lowest 25% of values.
Adjust the number of buckets according to thy wish:
=MAX(ROUNDUP(PERCENTRANK([Range],[OneCellOfTheRangeToTest]) *[NumberOfBuckets],0),1)
The number of observation in each bucket will be equal or almost equal. For example if you have a 100 observations and you want to split it into 3 buckets (like in your example) then the buckets will contain 33, 33, 34 observations. So almost equal. You do not have to worry about that - the formula works that out for you.
May be not quite what you were looking for but how about using conditional formatting functionality of Excel
EDIT: As an alternate you could create a vba function that acts as a formula that will do the calulation for you. something like
Function getBucket(rng As Range) As String
Dim strReturn As String
Select Case rng.Value
Case 0 to 10
strReturn = "Small"
Case 11 To 20
strReturn = "Medium"
Case 21 To 30
strReturn = "Large"
Case 31 To 40
strReturn = "Huge"
Case Else
strReturn = "OMG!!!"
End Select
getBucket = strReturn
End Function
I prefer to label buckets with a numeric formula. If the bucket size is 10 then this labels the buckets 0,1,2,...
=INT(A1/10)
If you put the bucket size 10 in a separate cell you can easily vary it.
If cell B1 contains the bucket (0,1,2,...) and column 6 contains the names Low, Medium, High then this formula converts a bucket to a name:
=INDIRECT(ADDRESS(1+B1,6))
Alternatively, this labels the buckets with the least value in the set, i.e. 0,10,20,...
=10*INT(A1/10)
or this labels them with the range 0-10,10-20,20-30,...
=10*INT(A1/10) & "-" & (10*INT(A1/10)+10)
The right tool for that is to create a range with your limits and the corresponding names.
You can then use the vlookup()
function, with the 4th parameter set to True
to create a range lookup.
Note: my PC uses ;
as separator, yours might use ,
.
Adjust formula according to your regional settings.