Rank with condition - excel

I'm searching for a formula which could rank a value from a subset of a range.
Let's say Col.A is Departement and Col.B is value.
I want a formula which can rank the value from all the other value of this departement.
I have tried things
{=rank(value,if(myrange=condition,myrange),0)}
Does not work.
I have managed to do the oposite - retrieving the value of a certain rank with :
{=small(if(myrange=condition,myrange),rank i want)}
I don't understand why my first formula fail.
Excpected result would be the rank of the value from it's subset of value which is all cells where the condition is true.

For such scenarios (ranking a subset of data), I find using SUMPRODUCT much easier:
=SUMPRODUCT(($A$2:$A$12=A2)*(B2<$B$2:$B$12))+1
This is for descending order. Result:

Although Excel has a RANK function, there is no RANKIF function to
perform a conditional rank. However, you can easily create a
conditional RANK with the COUNTIFS function. Exceljet
Some sample data:
| Dep | Val |
|-----|-----|
| A | 5 |
| A | 3 |
| A | 6 |
| A | 6 |
| B | 3 |
| B | 8 |
| B | 2 |
| C | 9 |
| C | 5 |
| C | 7 |
Let's put the COUNTIFS in there:
Formula in C2 for descending:
=COUNTIFS($A$2:$A$11,A2,$B$2:$B$11,">"&B2)+1
Formula in D2 for ascending:
=COUNTIFS($A$2:$A$11,A2,$B$2:$B$11,"<"&B2)+1
Drag both down....

Related

Ignore empty filter criteria in COUNTIFS formula [duplicate]

This question already has an answer here:
Ignore empty filter criteria in SUMPRODUCT formula
(1 answer)
Closed 7 days ago.
| A | B | C | D | E
--|-------------|-------------|-------------|-------------------|---------------
1 | Product | Brand | Revenue | Filter Product | Product C
2 | Product A | Brand 1 | 500 | Fitler Brand | Brand 1
3 | Product A | Brand 2 | 600 | Result | 2
4 | Product B | Brand 2 | 400 | |
5 | Product C | Brand 3 | 350 | |
6 | Product C | Brand 1 | 800 | |
7 | Product C | Brand 1 | 700 | |
In cell E3 I want to count the products based on the criteria that are entered in cell E1 and E2.
Therefore, I implemented this formula which works perfectly:
=SUMPRODUCT(COUNTIFS($A$2:$A$7;$E$1;$B$2:$B$7;$E$2))
However, now I want to implement in the formula a logic that if cell E1 or E2 is empty those filters are ignored.
For example if cell E1 is empty and cell E2="Brand 1", the result would be 3.
With reference to the answer in this question I assume the solution looks something like this:
=SUMPRODUCT(COUNTIFS($A$2:$A$7;IF($E$1="";1;$A$2:$A$7);IF($E$2="";1;$B$2:$B$7)))
However, I have not been able to make the formula work correctly.
Do you have any idea how I have to modify it?
=IFERROR(ROWS(FILTER(C2:C7,(IF(E1="",1,A2:A7=E1))*(IF(E2="",1,+B2:B7=E2)))),0)
Using FILTER you can count the rows of the result. In case no matches from the values in E1 or E2 the filter and the count of rows will return an error, hence the IFERROR(formula,0)
PS replacing ROWS with SUM is an alternative solution to your previous question.
With SUMPRODUCT you could use something like this:
=SUMPRODUCT((LEN(A2:A7)>0)*(IF(E1="",1,A2:A7=E1))*(IF(E2="",1,B2:B7=E2)))

Combining rows of a table using similar cells of one of its columns in Excel

I have a table (1) in Excel, with two columns, in which at the first column (A) there are some numbers and at the second column (B) there are some letters. I want to have a method to make another table (2) from (1) to put different letters at the first column then to put in each row the numbers that were corresponded to letters in table (1).
For example, let the table (1) is:
| A | B |
|---|---|
| 1 | a |
| 1 | b |
| 2 | a |
| 2 | c |
| 3 | b |
| 4 | b |
What is a method in Excel which make the following combination table:
| a | 1 | 2 | |
| b | 1 | 3 | 4 |
| c | 2 | | |
in which letters are in first column and in each row there are the numbers that were in relationship with the row's letter in table (1)?
As per below screenshot use below formula to C1 cell.
=UNIQUE(B1:B6)
And following formula to D2 cell then drag down
=TRANSPOSE(UNIQUE(FILTER($A$1:$A$6,$B$1:$B$6=C1)))

Formula to multiply all rows in a column after adding 1 to each one of them, and subtracting 1 after all of the products

How can I automate this formula to a large number of cells without needing to manually summing them?
I want to add 1 to each row in a column and then multiply it by the other rows with the same criteria, and after all, I want to subtract 1 of the total value, like this:
=(C2+1)*(C3+1)*(C4+1)*(C5+1)*(C6+1)-1
google-sheets only:
PRODUCT of C2:C6+1 enforcing array context with ARRAYFORMULA:
=ARRAYFORMULA(PRODUCT(C2:C6+1))-1
THis should work:
=EXP(SUMPRODUCT(LN(C2:C+1)))-1
You can do this using two helper columns, where the first one contains the product, and the second the product minus one:
| A | B | C | D | E
==+===+===+====+============+======
1 | | | | 1 | =D1-1
2 | | | x1 | =D1*(C2+1) | =D2-1
3 | | | x2 | =D2*(C3+1) | =D3-1
4 | | | x3 | =D3*(C4+1) | =D4-1
5 | | | x4 | =D4*(C5+1) | =D5-1
Dragging the formulas down should fill them in as expected. Column "E" contains the information you're looking for.

Spreadsheet Formula to Sum Values Over A if B is not in a List of Values

I have a table that looks the following:
| A | B | C |
| 40 | 1 | 1 |
| 180 | 2 | 2 |
| 34 | 1 |
| 2345 | 3 |
| 23 | 1 |
| 1 | 2 |
| 4354 | 3 |
| 2 | 2 |
| 343 | 4 |
| 2 | 2 |
| 45 | 1 |
| 23 | 1 |
| 4556 | 3 |
I want to get the sum of all fields in A where B is neither 1 nor 2 or any other value from colum C. This column contains the values of B where values from A should not be considered for the sum.
I do not know which values B might contain, those values are random and could grow larger, I just wanted to make the example small. My current solution is
{=SUMIF(B1:B13,C1:C2,A1:A13)}
so i can set the lines that should be excluded from the sum in column C. Unfortunately, the current solution does not solve my problem but something different -- it sums up the corresponding entries by value in C. My preferred solution would look something like
=SUMIF(B1:B13,"<>{1, 2}",A1:A13)
=SUMIF(B1:B13,"<>"&C1:C2,A1:A13)
if that were possible (it isn't). I would like to have:
a field (with a list, for example) or column where i can put in the values of B that I do not want to be part of the sum over A.
a method that works with Open Office as well as Excel. I prefer an OO solution.
You could use an array formula so that you can multiply each value in A with a condition. That condition can be any valid Excel formula, so, for instance, you could use MATCH to test if the B value occurs in C:
=SUM((A1:A13)*ISNA(MATCH(B1:B13,$C:$C,0)))
The ISNA function returns TRUE when the match fails, which in a multiplication is used as a numerical value 1. FALSE will make the product 0.
Make sure to enter this as an array formula with Ctrl+Shift+Enter

How to assing a given value randomly in Excel?

I have 30 peoples waiting for result out of 10. I want to assign each of 30 peoples: 7, 8 or 10 result randomly.
Peoples in excel are:
A1:A30
Random numbers in Excel
B1, C1, D1 //Which means B1=8, C1=7 and D1=10
The random number to keep on:
E1 to E30
To get a random integer in a range, use the randbetween(start,end) function. This will produce a random integer between the start and end parameters inclusively. Since your numbers are not contiguous, you can simply index them and perform a lookup using vlookup(randbetween(startindex,endindex),...) to get a random value from the table.
Check out this Example Excel File I created.
Use the following steps to get your desired result:
List the people in column A
Create a lookup table in Columns G and H
containing your desired result values.
In your result column (column E in the example below), add the formula: =vlookup(randbetween(1,3),G:H,2,false)
Column E will now contain either the numbers 7,8,or 10 for each person.
If you want to generalize this and allow any number of different values in your result lookup table, you can change the formula in column E to: =vlookup(randbetween(1,counta(G:G)-1),G:H,2,false).
Note: The -1 is only needed if your lookup table has a header row.
This will select a random value from all non-empty rows in your result lookup table.
In the example below, I added a header row to row 1, and the people start in row 2, for clarity.
+---+---------+---+---+---+--------+---+-----------+--------------+
| | A | B | C | D | E | F | G | H |
+---+---------+---+---+---+--------+---+-----------+--------------+
| 1 | Names | | | | RESULT | | Result ID | RESULT Value |
+---+---------+---+---+---+--------+---+-----------+--------------+
| 2 | Person1 | | | | 7 | | 1 | 7 |
+---+---------+---+---+---+--------+---+-----------+--------------+
| 3 | Person2 | | | | 7 | | 2 | 8 |
+---+---------+---+---+---+--------+---+-----------+--------------+
| 4 | Person3 | | | | 10 | | 3 | 10 |
+---+---------+---+---+---+--------+---+-----------+--------------+
| 5 | Person4 | | | | 8 | | | |
+---+---------+---+---+---+--------+---+-----------+--------------+

Resources