Excel formula to get ranking position - excel

I have a table of people with points. The more points, the higher your position. If you have the same points you are equal first, second etc.
| A | B | C
1 | name | position | points
2 | person1 | 1 | 10
3 | person2 | 2 | 9
4 | person3 | 2 | 9
5 | person4 | 2 | 9
6 | person5 | 5 | 8
7 | person6 | 6 | 7
Using an Excel formula, how can I automatically determine the position? I'm currently using an IF statement that works fine for 5 or 6 matching positions, but I can't add 30+ if statements because there's a limit to the formula.
=IF(C7=C2,B2,IF(C7=C3,B2+5,IF(C7=C4,B3+4,....
So if the points column is the same as the position above then it's the same position value. If the points are less than above then it drops a position so the previous row position +1. But if the row above that is the same then it's the previous position +2 and so on.

You could also use the RANK function
=RANK(C2,$C$2:$C$7,0)
It would return data like your example:
| A | B | C
1 | name | position | points
2 | person1 | 1 | 10
3 | person2 | 2 | 9
4 | person3 | 2 | 9
5 | person4 | 2 | 9
6 | person5 | 5 | 8
7 | person6 | 6 | 7
The 'Points' column needs to be sorted into descending order.

Type this to B3, and then pull it to the rest of the rows:
=IF(C3=C2,B2,B2+COUNTIF($C$1:$C3,C2))
What it does is:
If my points equals the previous points, I have the same position.
Othewise count the players with the same score as the previous one, and add their numbers to the previous player's position.

You can use the RANK function in Excel without necessarily sorting the data. Type =RANK(C2,$C$2:$C$7). Excel will find the relative position of the data in C2 and display the answer. Copy the formula through to C7 by dragging the small node at the right end of the cell cursor.

Try this in your forth column
=COUNTIF(B:B; ">" & B2) + 1
Replace B2 with B3 for next row and so on.
What this does is it counts how many records have more points then current one and then this adds current record position (+1 part).

If your C-column is sorted, you can check whether the current row is equal to your last row. If not, use the current row number as the ranking-position, otherwise use the value from above (value for b3):
=IF(C3=C2, B2, ROW()-1)
You can use the LARGE function to get the n-th highest value in case your C-column is not sorted:
=LARGE(C2:C7,3)

The way I've done this, which is a bit convoluted, is as follows:
Sort rows by the points in descending order
Create an additional column (D) starting at D2 with numbers 1,2,3,... total number of positions
In the cell for the actual positions (D2) use the formula if(C2=C1), D2, C1). This checks if the points in this row are the same as the points in the previous row. If it is it gives you the position of the previous row, otherwise it uses the value from column D and thus handle people with equal positions.
Copy this formula down the entire column
Copy the positions column(C), then paste special >> values to overwrite the formula with positions
Resort the rows to their original order
That's worked for me! If there's a better way I'd love to know it!

Related

Excel - Check if Value of Two Columns are new in a List and Passing a new ID to them

Good Morning,
I'm trying to formulate something in Excel that allow us to check if the value of two columns are new in a list, and if so, assign a new ID for them. If it's not, let it "Blank" or Assign the same ID that have been assigned before(Either way would work for me).
I'm trying to use something with Count.if, but it doesn't fit. As i'm thinking about this for some time, i decided to look for help.
What i want to do is a formula that solves the "Formula" Columns below:
Space|Name|*Formula*
1 | AB | 1
1 | AB | 1
1 | AB | 1
1 | CA | 2
2 | DD | 3
2 | EE | 4
2 | EE | 4
3 | SS | 5
3 | SS | 5
1 | ZZ | 6
1 | AB | 1
Sequential Numbering of Groups of Data
In cell C2 use the following array formula (Ctrl,Shift+Enter):
=IF(COUNTIFS(A$2:A2,A2,B$2:B2,B2)=1,MAX(C$1:C1)+1,
INDEX(C$1:C1,MATCH(1,(A$1:A1=A2)*(B$1:B1=B2),0)))
Then copy C2 and pastedown from C3 to the last cell.
If you're satisfied with just numbering each first occurrence then use the following formula:
=IF(COUNTIFS(A$2:A2,A2,B$2:B2,B2)=1,MAX(C$1:C1)+1,"")
Both solutions use the headers i.e. the headers must not be numbers.
If you don't mind non-sequential numbering, you can just return the index of the first match found as your identifier:
Copy into C2, then fill down as necessary. The match row stop may need alteration based on how much data you have
=MATCH(A2&"#"&B2, A$2:A$100&"#"&B$2:B$100,0)
Or as an array formula (only need to place in C2);
=MATCH(A2:A11&"#"&B2:B11, A2:A11&"#"&B2:B11,0)

Need some kind of pivotal table without agregation in Excel

I struck with problem of getting reports from table, that look like this:
C1| C2 | C3 | C4
A | 2015-05-15 | 34 | 4
A | 2015-03-12 | -4 | 5
A | 2014-03-12 | 24 | 8
B | 2015-11-10 | -4 | 5
B | 2015-06-12 | 3 | 5
C | 2013-05-12 | 3 | 5
...
600+ rows
...
So I need to make a diagram by different value columns (C3 and C4) grouping by values in the first column. In usual case it is achieved with to separate table which a looks like this (e.g. for col3):
A | B | C | ....
34 | -4 | 3 | ....
-4 | 3 | | ....
24 | | | ....
For col4, I need a table with the similar layout. So in short, I need to make some pivotal table by without aggregation on value per term. Is it possible to get such small table with the original table? If you can offer some other layout for original data which will be more suitable (and easier, in ideal with standard excel functions) for this task, fell free to offer - with some Python script I can resave it.
Find a simple solution: just download tool Tableau. It affords to create very flexible graphs based on raw data, freely place any col as row and vice versa, groping also available.
First, I will assume that C1,C2,C3,C4 are column headings in A1:D1 and the data is in A2:D1000
In F1:H1 place C3,C3,C3
In F2:H2 place A,B,C
In J1:L1 place C4,C4,C4
In J2:L2 place A,B,C
In F3 place the following array formula:
=IFERROR(INDEX(OFFSET($A$2:$A$1000,0,MATCH(F$1,$A$1:$D$1,0)-1),SMALL(IF($A$2:$A$1000=F$2,ROW($A$2:$A$1000)-ROW(A$2)+1),ROWS(F$2:F2))),"")
Don't forget to use Ctrl+Shift+Enter to make it an array formula instead of just using Enter for a normal formula.
Copy F3 to F4:F7, G3:H7 and J3:L7
You end up with something that looks like this:
| A B C D E F G H I J K L
----|--------------------------------------------------------------------
1 | C1 C2 C3 C4 C3 C3 C3 C4 C4 C4
2 | A 15/05/2015 34 4 A B C A B C
3 | A 12/03/2015 -4 5 34 -4 3 4 5 5
4 | A 12/03/2014 24 8 -4 3 5 5
5 | B 10/11/2015 -4 5 24 8
6 | B 12/06/2015 3 5
7 | C 12/05/2013 3 5
Decomposing the formula in F3:
=IFERROR(INDEX(source column,SMALL(filtered row numbers,ranking)),"")
Where:
source column is OFFSET($A$2:$A$1000,0,MATCH(F$1,$A$1:$D$1,0)-1)
filtered row numbers is IF($A$2:$A$1000=F$2,row numbers)
row numbers is ROW($A$2:$A$1000)-ROW(A$2)+1
ranking is ROWS(F$2:F2)
How the formula works is a multipart explanation:
IFERROR(formula,"") If the embedded formula produces an error then we display an empty cell instead. This is useful since we don't know how many results we will get.
INDEX(range,row) Get the value in the row we want to see. The row number here is dynamically generated based on whether the data matches the criteria.
SMALL(array,k) Extract the kth smallest value in the array. The array is the filtered values. k is just a number depending on which row in F we put the formula in.
IF(criteria,value) Based on the criteria either produces the value or FALSE.
ROW(cell) The row number of the cell
ROWS(range) The size of the range
So in the array formula:
ROW($A$2:$A$1000)-ROW(A$2)+1 is a list of all the row numbers in the range starting at 1
IF($A$2:$A$1000=F$2,ROW($A$2:$A$1000)-ROW(A$2)+1) is a list of just those row numbers that match the criteria
SMALL takes the filtered list and returns the kth smallest filtered row number which means that F3 gets the first one, F4 gets the second one, etc
INDEX grabs the data at that row number and displays it
I got the idea for this from http://www.exceltactics.com/make-filtered-list-sub-arrays-excel-using-small/ and on that page is a really good explanation of how it all works.

Display Value in cell Y based on greater than, less than of cell X

Here's the scenario. I have a large spreadsheet of candidates for NHS at my school that are given a score by several teachers, community members, etc. I average out their score and then based on that number they are given a score/value from a rubric. I am looking for a formula that will read the value of cell X (their average score) and display a specific value in cell Y(their rubric score). The following is the criteria:
value<2.0, display 0
value>2.0 value<3.0, display 1
value>3.0 value<3.5, display 2
value>3.5 value<3.75, display 3
value>3.75, display 4
I tried looking this up and the closest I found was a formula that I modified to look like this:
=IF(I10="AVERAGE_CHARACTER",IF(I10<2,0,IF(AND(I10>2,I11<3),1,IF(AND(I10>3,I11<3.5),2,IF(AND(I10>3.5,I11<3,75),3,IF(I11>3.75,4,0))))))
All it says is FALSE in the cell. Not sure if I'm using the wrong formula or have a typo in the formula. Thoughts? If there is an alternate or easier method, I'm open for suggestions.
Thanks!
source: http://www.excelforum.com/excel-formulas-and-functions/575953-greater-than-x-but-less-than-y.html
It's easy if you keep the thresholds and the rubric in separate arrays:
=LOOKUP(A1,{0,2,3,3.5,3.75},{0,1,2,3,4})
You might use something like: (value to be changed in A1)
=VLOOKUP(A1,{0,0;2,1;3,2;3.5,3;3.75,4},2)
or having a table like this: (value to be changed in C1)
| A | B |
1 | 0 | 0 |
2 | 2 | 1 |
3 | 3 | 2 |
4 | 3.5 | 3 |
5 | 3.75 | 4 |
=VLOOKUP(C1,A1:B5,2)

How to get a range of values from an openoffice calc formula?

Am encountered an issue on openOffice Calc.
I need to get a range of values from a formula, that can be used in a dropdownlist/validity.
I have a sheet with following data.
A B C
+---------------
1 | 10 x
2 | 20 x
3 | 30 y
4 | 40 z
5 | 50 x
6 |---------------
Here I need a list of values of 'A' where values 'B' equals 'x'.
I have checked with LOOKUP/INDEX functions, but it returns a single value(first occurrence) not a range.
Try this formula:
=IFERROR(INDEX($A$1:$A$5, SMALL(IF($B$1:$B$5="x",ROW($B$1:$B$5),9^99),ROW())),"")
^-------^ ^-------^ ^ ^-------^ ^--^
| | | | +-> Random big number
| | | +-> Range to check
| | +-> Value to check
| +-> Range to check
+-> Range to return
You'll need to use Ctrl+Shift+Enter to make it work, then drag the formula down.
If you start on row 2, you'll have to use ROW()-1 for it to work. It's generally ROW()-(k-1) where k is the row number you're using the formula first.

How to automatically delete rows in Excel

Consider the following (partial) Excel worksheet:
A | B | C | D
---+-------------+-------+-------
id | date | var_a | var_b
1 | 2011-03-12 | 200 | 34.22
1 | 2011-03-13 | 203 | 35.13
1 | 2011-03-14 | 205 | 34.14
1 | 2011-03-15 | 207 | 54.88
1 | 2011-03-16 | 208 | 12.01
1 | 2011-03-18 | 203 | 76.10
1 | 2011-03-19 | 210 | 14.86
1 | 2011-03-20 | 200 | 25.45
. | . | . | .
. | . | . | .
2 | 2011-03-12 | 200 | 34.22
2 | 2011-03-13 | 203 | 35.13
2 | 2011-03-14 | 205 | 34.14
2 | 2011-03-15 | 207 | 54.88
2 | 2011-03-16 | 208 | 12.01
2 | 2011-03-18 | 203 | 76.10
2 | 2011-03-19 | 210 | 14.86
2 | 2011-03-20 | 200 | 25.45
. | . | . | .
. | . | . | .
In reality, there are over 5.000 rows. I need to delete all rows which date falls on a saturday or sunday. In the example, March 12 and 13 (2011-03-12/13) and March 19 and 20 are Saturdays and Sundays. I cannot just delete every nth rows, since there might be days missing in the list (as is the case here with 2011-03-17).
Is this possible to do with either a formula or VBScript? I have never written a VBScript macro before (I have never had a use for it) so I would appreciate some help.
If you only need to do this once, this is what I would do. This should preserve the order, but if you're really worried about it, read very end of the post:
Add a new column, call it "Is Weekend". In it, put =if(WEEKDAY(B2, 2) > 5, 1, 0). Drag that formula down for the entire table.
Filter the columns. To do that, select the entire table (click on any table cell then hit Ctrl-A), then
On Excel 2007+, go to Data-> click "Filter"
On Excel 2003, go to Data->Filter->Auto Filter.
Sort everything by last column (Is Weekend) in descending order. This should put all weekend rows together without altering the order among the other rows.
Delete all rows with 1 in "Is Weeked" column. Delete that column.
If you're really worried about preserving order, before you do the above, you can do the following:
Add a new column called "Position". Put 1 in the first row, 2 in the second row, select them and drag it down to the bottom so every row has its own position number in increasing order.
Perform the filtering as above.
After you're done, sort everything in ascending order by "Position" column.
The trick is that you don't need to delete those rows, you need to replace their values for C and D with 0. This is easiest done with IF() and WEEKDAY() within two new columns C' and D' referencing C and D. Feel free to then just delete C and D.
You can do this in one go using an array formula. In cell E2, enter the following formula (on one line), and confirm with Ctrl-Shift-Enter (as opposed to the regular Enter)
=INDEX($A$2:$D$5000, SMALL(IF(WEEKDAY($B$2:$B$5000,2)>5, "",
ROW($B$2:$B$5000)-MIN(ROW($B$2:$B$5000))+1), ROW(A1)),COLUMN(A1))
5000 indicates the number of rows in your spreadsheet. After this, the formula should have curly braces around it to indicate it is an array formula. E2 should have the value 1. Then select cell E2 and drag the lower-right corner of the cell to the right until 4 cells are covered. Then drag the lower-right corner of the 4-cell-selection all the way down. At the bottom you will see rows containing #NUM!, one for each deleted row. You can delete those in the regular way.
In stead of starting off in cell E2, you could start off in cell A2 of a new sheet. In that case, you need to prepend the original sheet name to each reference in the formula, as in OriginalSheet!$A$2
This formula is an adaption from the one given in Excel: Remove blank cells
In case you decide to delete the rows, please make sure to run the VBA code from the last row to the first row. Here is a piece of code just written from memory to show you the idea of running from bottom to the top.
For i = Selection.Rows.Count To 1 Step -1
If WEEKDAY(Cells(r, 2),2) > 5 Then
Selection.Rows(i).EntireRow.Delete
End If
Next i

Resources