Excel formula to get the lowest n values from a range - excel

I have some values in a column which are not necesarily sorted. Then I want to find the average of the lowest n values from the column with the values.
So let's take the example above. Say I need to average n=3 lowest values from the column above with values ranging from A1 to A10. The result will be the average of 1 (taken from A1), 2 (taken from A6) and 3 (taken from A2). I am thinking of something like AVERAGE(LOWEST_N(A1:A10, 3)) but I'm not sure it can be as simple as that.
Note: I can't sort the values on that specific column. I also do not wish to manually move the values to another column and sort them there, because I want to do this many multiple times and I need to automate the process.

You can use an array formula, using ctrl, shift and enter to confirm.
=AVERAGE(SMALL(A1:A10,ROW(1:3)))

Try this: =AVERAGEIF(A1:A10, "<4")

Related

Array formula to switch selection

I am trying to determine the top 3 depending on the selected criteria, amount or count. User can choose between the two. I have the formula to determine top 3 but I don't know how to modify it to take in account of user's selection. User's selection is in J2.
In this case, count is selected but as you can see, my formula spits out amount.
I think I need an array formula nesting choose or offset or something. The formula I have in the selected cell is
=INDEX($A$3:$A$35,MATCH(1,INDEX(($E$3:$E$35=LARGE($E$3:$E$35,ROWS(I$7:I7)))*(COUNTIF(I$7:I7,$A$3:$A$35)=0),),0))
which calculates top 3. How can I get that to change depending on user selection?
Edit: I realize I can have two sets of data for each criteria and do an offset to select between the two but figured one of you wizards can probably do it all in one. (This data is used to drive a graph.)
Edit2: sorry if it was too abstract. There are two columns. E and F. E is a list of amounts. F is a list of counts. I want to find the top 3 of both. But obviously only one at a time. Depending on what the user chooses.
As you can see, even though the selection is currently count (J7), the results show the top 3 by amounts.
By using the number selected in J2, I should be able to nest an offset function to grab the column desired yes? 1 for column E, 2 for column F. That's how I understand the function to work. However, my attempts to nest has failed because I believe I need an array formula which is beyond my skillz.
Edit3: see pic. It shows the top 3 by each criteria. How do I combine them?
You could combine it into one (non-array) formula. Here is a simple example which perhaps you can adapt to your situation.
This is the formula in J7. Change the 2 in J2 to 1 and it will return the largest value in E rather than F.
=INDEX(OFFSET($E$3:$E$35,,J2-1,,),MATCH(1,INDEX((OFFSET($E$3:$E$35,,J2-1,,)=LARGE(OFFSET($E$3:$E$35,,J2-1,,),ROWS(I$7:I7)))*COUNTIF(I$7:I7,$A$3:$A$35)=0),),0))

Excel: Sort column by specific names, than add the sum of the sorted items to separated cell

I have a column where I am going to add 3 specific strings ("zero","one","two").
These items will be sorted by default. I want a separated cell for the "zero" to search how many "zero" are there in the column and calculate the sum of them.
The problem is that every time when I use this document, the amount of "zero"-es will be different.
As far I understood your question is that you have a column with Multi names (Zero, One and Two) with a corresponding value cell and you want add the values of all the Zeros. Well as by this, the Sumif() function will help you good. See the picture at Following. see in the formula bar
and use Countif() to count the Zeros in the Column.

Excel Permutation Table without VBA

Is it possible to generate a table of permutations in Excel without using VBA and without using any "helper" sheets or rows/columns?
For N columns, there would be N! rows.
For example, the table for N=3 would look like this:
1 2 3
1 3 2
2 1 3
2 3 1
3 1 2
3 2 1
Open a blank worksheet and paste the following formula into cell A1. (I included line breaks for readability.)
= IF(ROW()<=FACT(COLUMN()-1),COLUMN(),
INDIRECT(ADDRESS(ROW()-FACT(SUMPRODUCT(((ROW()-1)>=FACT(ROW($A$2:$A$10)))+0)+1),
IF(COLUMN()=(SUMPRODUCT(((ROW()-1)>=FACT(ROW($A$2:$A$10)))+0)+2),1,COLUMN()+1))))
Simply drag this formula over N columns and then down N! rows in order to generate a full permutation table of order N.
A few things to note:
Because factorials grow very quickly, the formula above only works for N<=10. However, this isn't really a limitation because 10! = 3,628,800 which is a number that exceeds the maximum number of rows in Excel 2010 (which is 1,048,576). Therefore, Excel can't generate a permutation table for N=10 anyway.
If you want the top left of the table to be a cell other than A1, the formula can manually be modified to account for this shift. For example, if you want the table to start at A2 instead of A1, replace each instance of ROW() in the formula above with (ROW()-1).
Excluding the first row (which lists the numbers ascending) and the last row (which lists the numbers descending), the order in which the permutations are listed in this table are not in the same order as listed in the original question, but the pattern is still deterministic. See below for a screenshot of a permutation table using this formula of order 4, using conditional formatting to make it easy to spot the pattern of how the order of the permutations change as row numbers increase.
EDIT:
Another solution with all of the same properties as above except that the permutations are generated in a different order is the following:
= IF(ROW()<=FACT(COLUMN()-1),COLUMN(),
INDIRECT(ADDRESS(ROW()-FACT(SUMPRODUCT(((ROW()-1)>=FACT(ROW($A$2:$A$10)))+0)+1),COLUMN()))
+IF(ROW()<=FACT(COLUMN()),-1,
IF(INDIRECT(ADDRESS(ROW()-FACT(SUMPRODUCT(((ROW()-1)>=FACT(ROW($A$2:$A$10)))+0)+1),COLUMN()))
=INDIRECT(ADDRESS(ROW(),(SUMPRODUCT(((ROW()-1)>=FACT(ROW($A$2:$A$10)))+0)+2))),1,0)))
This formula is obviously longer than the first formula, but it still generally accomplishes the same thing: Open a blank worksheet and paste this formula into cell A1. Then drag the formula over N columns and then down N! rows in order to generate a full permutation table of order N.
As already stated, however, the order of the permutations changed as compared to the previous solution. The order of permutations in this solution is arguably better than that of the first solution because each column always contains "blocks" of numbers of the same size. See below for a screenshot of a permutation table using this formula of order 4, using conditional formatting to make it easy to spot the pattern of how the order of the permutations change as row numbers increase.
For those stumbling upon this in 2021 and beyond: if you have access to Power Query, a Cross join is a straightforward way to achieve this (and technically not VBA and doesn't use "helper" columns)
See documentation here.

Generate a 3rd column sequential number based on two columns data

I apologize if the title is misleading, but
I have an issue where I need to generate a sequential number in a third column based on comparing data from two different columns.
My data looks like this:
Before
The entry with the 1 is the first point, I need to use the value in the 'Back' column to find the same value in the 'Front' Column, then add +1 to the point, so the result looks like:
After
Because of the naming conventions used, sorting either column by value will not work.
Appreciate the help!
Assuming you have the initial 1, and your number column is C, front is D, back is E, this would start at row 2:
=INDEX(C:C,MATCH(INDEX(D:D,MATCH(D2,E:E,0),1),D:D,0),1)+1
Image: http://i.imgur.com/0XfdLrk.png
Did you establish whether your data has duplicates or incomplete sequences?
Here's another formula which should achieve what you want and also doesn't rely on you knowing where the sequence starts. Every sequence will start with 1.
This formula follows your image layout, putting values into column A with data in columns B and C. Please replace the ranges in the formula for columns A and C to cover all of your data. (Ideally, you would do this by inserting a table first and then selecting the data rows, which will cause Excel to put in the table column name instead.)
This is the formula to go into cell A2, assuming you have data in B2:C7
=IF(ISERROR(MATCH(B2,$C$2:$C$7,0)),1,INDEX($A$2:$A$7,MATCH(B2,$C$2:$C$7,0))+1)
Put this formula in D2 and fill down to identify which rows are the ends of sequences:
=ISERROR(MATCH(C2,$B$2:$B$7,0))
Put this formula in E2 and fill down to identify duplicates in the Front column:
=COUNTIF(B$2:B$7,B2)
You can then fill it right one column to also identify duplicates in Back.

Pulling value from cells in Excel based on top 5 value in a different column

Let's say column A has ten names in it, and column B ten values. I want the names of the people with the five highest column B values, in order, to populate on a different sheet. How would I do this? What if I wanted the lowest values?
you can also use vlookup to achieve the same but since your lookup value comes before the column you are looking up against then you need to use choose function to resolve this:
always using the same example table
put this formula in C2 to pull the top 5:
=VLOOKUP(LARGE($B$2:$B$99,ROW(1:1)),CHOOSE({2\1},$A$2:$A$99,$B$2:$B$99),2,0)
and put this in D2 to pull the low 5:
=VLOOKUP(SMALL($B$2:$B$99,ROW(1:1)),CHOOSE({2\1},$A$2:$A$99,$B$2:$B$99),2,0)
hope this works as well.
you can use the index matchfunction to achieve this:
Given the above example table:
Formula to pull top 5, put this in C2:
=INDEX($A$2:$A$99,MATCH(1,INDEX(($B$2:$B$99=LARGE($B$2:$B$99,ROWS(C$1:C1)))*(COUNTIF(C$1:C1,$A$2:$A$99)=0),),0))
Formula to pull low 5, put this in D2:
=INDEX($A$2:$A$99,MATCH(1,INDEX(($B$2:$B$99=SMALL($B$2:$B$99,ROWS(D$1:D1)))*(COUNTIF(D$1:D1,$A$2:$A$99)=0),),0))
For both, drag and fill down for 5 rows (because you want top/low 5). you can drag/fill down as many as you want.
you can adapt it to fit the lenght of your column by changing the $A$99 and $B$99 to any number of rows you have.
tell me if it works for you.

Resources