可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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
where if the value is 0 - 10 then put it Small. If the value is 10 - 20 put it in Medium, etc . . .
if there any elegant way of doing it besides having nested if statements all put together?
回答1:
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
回答2:
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.

回答3:
If all you need to do is count how many values fall in each category, then this is a classic statistics question and can be very elegantly solved with a "histogram."
In Excel, you use the Data Analysis Add-In (if you don't have it already, refer to the link below). Once you understand histograms, you can segregate your data into buckets - called "bins" - very quickly, easily adjust your bins, and automatically chart the data.
It's three simple steps: 1) Put your data in one column 2) Create a column for your bins (10, 20, 30, etc.) 3) Select Data --> Data Analysis --> Histogram and follow the instructions for selecting the data range and bins (you can put the results into a new worksheet and Chart the results from this same menu)
http://office.microsoft.com/en-us/excel-help/create-a-histogram-HP001098364.aspx
回答4:
You're looking for the LOOKUP function. please see the following page for more info:
Data Buckets (in a range)
回答5:
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.
回答6:
A nice way to create buckets is the LOOKUP() function.
In this example contains cell A1 is a count of days. The vthe second parameter is a list of values. The third parameter is the list of bucket names.
=LOOKUP(A1,{0,7,14,31,90,180,360},{"0-6","7-13","14-30","31-89","90-179","180-359",">360"})
回答7:
Maybe this could help you:
=IF(N6<10,"0-10",IF(N6<20,"10-20",IF(N6<30,"20-30",IF(N6<40,"30-40",IF(N6<50,"40-50")))))
Just replace the values and the text to small, medium and large.
回答8:
Here is a solution which:
- Is self contained
- Does not require VBA
- Is not limited in the same way as IF regarding bucket maximums
- Does not require precise values as LOOKUP does
=INDEX({"Small","Medium","Large"},LARGE(IF([INPUT_VALUE]>{0,11,21},{1,2,3}),1))
Replace [INPUT_VALUE] with the appropriate cell reference and make sure to press Ctrl+Shift+Enter as this is an array formula.
Each of the array constants can be expanded to be arbitrarily long; as long as the formula does not exceed Excel's maximum of 8,192 characters. The first constant should contain the return values, the second should contain ordered thresholds,and the third should simply be ascending integers.
回答9:
If conditions is the best way to do it. If u want the count use pivot table of buckets. It's the easiest way and the if conditions can go for more than 5-6 buckets too
回答10:
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)