Find last occurrence of specific value in a row - excel

I have a table that keeps scores from fantasy football league. The lowest scoring week is not included in the total.
I'm able to find the lowest score using the =min function [=min(B2:R2)]
I can find the first instance using the =match function. [=MATCH(S2,B2:R2,0)]
However I would like a formula that returns the latest occurrence of the lowest scoring week.
For example Portia lowest score is 8 the first occurrence is week 4 but I would like it to return the latest occurrence which is week 11

You can also do this using LOOKUP function and avoiding array formulas, e.g. assuming S2 has the minimum value you can get the last week with that value with this formula in T2 copied down
=LOOKUP(2,1/(B2:R2=S2),B$1:R$1)
This works because (B2:R2=S2) returns an array of TRUE/FALSE values, and then dividing 1 by that array gives you an array of 1s or #DIV/0! errors. When you use 2 as the lookup value on that array it won't find any 2s so will therefore match with the last number (the last 1) in the array. That corresponds to the last week with your smallest value so using the top row as the "return vector" means that the formula returns the corresponding week number as required

You will need to use an Array Formula to achieve this. The following will return the "highest" lowest value if you are using columns B:R as the data columns and column T as the Low Week column. You need to enter this as an array (CSE) formula by copying and pasting it into cell T2 and pressing Ctrl+Shift+Enter.
=IFERROR(INDEX($A$1:$R$1,1,SMALL(IF(B2:R2=MIN(B2:R2),COLUMN(B2:R2),FALSE),COUNTIF(B2:R2,MIN(B2:R2)))),"")
Explanation
First, the COUNTIF(B2:R2,MIN(B2:R2)) will count the number of times the minimum value occurs. This is needed because a simpleMIN(B2:R2) will only grab the first minimum value, not the nth minimum value.
Next, the IF(B2:R2=MIN(B2:R2),COLUMN(B2:R2),FALSE) is the actual array formula part of the equation (the reason why you need to use Ctrl+Shift+Enter). It will only return the references for when you have a minimum and returning FALSE for all other entries greater than the minimum. Now, you have an array of only the column numbers the smallest values in the dataset.
Then, the SMALL(IF(B2:R2=MIN(B2:R2),COLUMN(B2:R2),FALSE),COUNTIF(B2:R2,MIN(B2:R2))) will take the column numbers of the smallest values and find the latest occurrence of this, which comes from the COUNTIF(B2:R2,MIN(B2:R2)) code.
Now that the last smallest occurrences' column number is know, you can use the INDEX function to find the value in the first row INDEX($A$1:$R$1,1.
Finally, the IFERROR will display the Low Week row if the SMALL function finds a match, otherwise it will display a blank cell. This could be used to copy this array formula further down the page for rows that you don't yet have users for.
Result

Related

Excel match, sum and subtract from a single total

In the table below, IF C12:C21 match either D3 or e4, I want to sum the SWAG column per row and then subtract either D5 or E5 (based on the match) from the additive sum per column until I know that I've reached the value in either D5 or E5 (based on the team match)
I'm not sure if I understand correctly what you mean, since you did not give an example of how the result you're looking for would look in given data. But this might be what you mean or at least usable to get to what you want:
=LET(swag,D12:D21,
s,SEQUENCE(ROWS(swag)),
r,MIN(
IFERROR(XMATCH(D5,SCAN(0,swag,LAMBDA(a,b,IF(OFFSET(b,,-1)=D4,a+b,a))),1),9^9),
IFERROR(XMATCH(E5,SCAN(0,swag,LAMBDA(a,b,IF(OFFSET(b,,-1)=E4,a+b,a))),1),9^9)),
IF(s=r,OFFSET(swag,,-1),""))
This uses the formula SCAN to conditionally sum the SWAG scores matching the correct team. Column F & G in the screenshot below demonstrate what SCAN does.
The MIN part of the formula compares the first matches equal to or greater than the values in row 4 to the scan value of it's team. If it results in no match it will give a high number as a result 9^9, so it will not be the MIN value.
The min value is the nth row in the SCAN ranges or if both result in 9^9 it'll result in that high value.
Then, if a sequence to the number of rows of the swag range equals the min value it'll show the team name of that row. If both didn't match they will not have a match to the sequence and all rows remain blank.

In Excel, how do I get the header corresponding to the max value from a subset of a range?

I'm pushing beyond my Excel knowledge here. I'm trying to do a poll like thing in Excel. My problem lies on showing the selected result. Here's what I have so far:
I need to select the header corresponding to the cell with the highest value in the range B2:G2 (type 1). However, if there's a tie, I need to select the header corresponding to the highest value in the range B3:G3 amongst the cells with highest values in the range B2:G2.
In my sample, column "bb" and "cc" both share highest value on type 1 (5). So, in order to determine the winner, I need to compare the highest value for type 2 between them. Since "bb" is 0 and "cc" is 1, I expect "cc" as final result.
Components for formula are below:
J2: Displays the count of cells on line 2 with the highest value in the range. So, 2. I did that with COUNTIF comparing with MAX.
K2: Displays the first header it finds with the highest value on line 2. I managed with the following formula:
=INDEX($B$1:$G$1;0;MATCH(MAX($B$2:$G$2);$B$2:$G$2;0))
To be honest, I don't fully understand that formula. Did it with help of tutorials from the internet.
I2: Displays "TIE" when there's a tie on range B2:G2. Otherwise display the winning header (K2).
J3: Displays the number of cells with the maximum value on range B3:G3 but only considering winning cells from line 2. I did that with COUNTIFS.
=COUNTIFS(B3:G3;LARGE(B3:G3;1);B2:G2;MAX(B2:G2))
Edit: Just found out by entering number "4" on B3 that this formula above is also not working...
I3: Should follow the same pattern as the cell above. Displays "TIE" when there's still a TIE. Otherwise would display winning header (to be presented on K3).
K3: I don't know what to put here. Probably because I don't quite understand that formula with INDEX, MATCH and so on, I can't figure out a way to check the highest value between the two "winning" columns from the line above and get the header.
Could somebody help me with this?
First, let's establish if there is a tie. As you have discovered, you can do this by counting how many times the highest number appears in the range.
=COUNTIF($B2:$G2;MAX($B2:$G2))
If that count is more than 1, then there is a tie.
=IF(COUNTIF($B2:$G2;MAX($B2:$G2))>1;"TIE";"no tie")
In case of a tie you want to involve the values in row 3 as a tie breaker. We could add them to the values in row 2 using this array formula. You must confirm the array formula with Ctrl+Shift+Enter, not just Enter, otherwise it won't work.
=INDEX($B$1:$G$1,MATCH(MAX(((IF(B2:G2=MAX(B2:G2),MAX(B2:G2),0))+B3:G3)),INDEX((B2:G2+B3:G3),0)))
You only want to factor in row 3 if there is a tie, though, so you can re-use the IF statement from above and replace the "tie" in the formula above with the array formula and remember to press Ctrl+Shift+Enter!!
=IF(COUNTIF($B$2:$G$2,MAX($B$2:$G$2))>1,INDEX($B$1:$G$1,MATCH(MAX(((IF(B2:G2=MAX(B2:G2),MAX(B2:G2),0))+B3:G3)),INDEX((B2:G2+B3:G3),0))),"no tie")
You already have the formula to look up the value if there is no tie.
My system uses the comma as the list separator. I have manually replaced these with semicolons in the formulas I posted, but please bear with me if I may have missed one.
Now you can copy these formulas down to row 3. If there is a tie in the data in row 3, you will need data in row 4 to break the tie.
To understand the Index/Match combo, start with your first formula and read it from the inside out. The Max() finds the largest number. The Match() returns the position, i.e. column number, of the largest number in the range B2 to G2, i.e. 2 (the second column in the range). Index looks at B1 to G1 and returns the column value from the position that the Match returned, i.e. the 2nd column, which is the text bb.
Using row 3 as the tie breaker, the formula works pretty much the same, only that rows 2 and 3 are added together when the value in row 2 is the Max value and then that number is used to find the Max and the Match.
Here is an approach with sumproducts. I dont really inderstand what results you want in I3, J3, and K3. will try to workout.
I2:
=IF(SUMPRODUCT(--(B2:G2=MAX(B2:G2)))>1,"TIE","")
J2:
=SUMPRODUCT(--(B2:G2=MAX(B2:G2)))
K2:
=IF(B7>1,OFFSET(B1,0,SUMPRODUCT(--(B3:G3=MAX(B3:G3))*--(B2:G2=MAX(B2:G2))*{0,1,2,3,4,5})),OFFSET(B1,0,SUMPRODUCT(--(B2:G2=MAX(B2:G2))*{0,1,2,3,4,5})))
the {0,1,2,3,4,5} refers to the number of headers, if there are more, this array needs to changed

How can I choose the highest number in a row, and multiply it automatically with a value in the same column?

I have a table in excel that can be seen below.
I want to choose the highest number in the "RPD" row and multiply it with the values that are in the same column.
So in this case the formula would take July column and multiply all the values there.
The problem is that I want to do this automatically, so when the order of values in "RPD" row changes the calculation changes automatically, still chooses the highest value in "RPD" row and multiplies it with all the values in the same column.
I also want to do this for the second highest value and so on...
So I would end up with a new row where the first column has the values for july multiplied and so on.
Thanks in advance.
You may need to use the =LARGE(matrix, k) function; where matrix will be the RPD numbers and K-esim largest number. And fix the range of your matrix.
Change MAIOIR to LARGE (i'm using it in pt_BR).
For the 1st one, the formula will be:
=LARGE(C5:N5; B9)*C4*C6
Then will have to lock the parameters by using $
=LARGE($C$5:$N$5; $B9)*C$4*C$6
Output:

When row contains a value, average other cells in same column

Let's say I have Row 21 titled "Stadium". Cells in this row contain any integer between 1 and 24. I need to create another cell with some formula that will do the following:
Find all cells in Row 21 that contain the value (integer) "6". Then, it needs to average the sum of all of the cells that are a given number of cells (such as nineteen) above the cells containing 6. For example:
The Spreadsheet I'm Using
Since Row 21 (Stadium) contains the value 6 twice, I need the highlighted cell (which I chose randomly) to output the average of cells B2 and E2 (which are nineteen cells above). So whatever formula I put in should output 11.5 which is the average number of Boost items obtained for every Stadium #6 event. If I wanted to find the average number of Glide items obtained for every Stadium #3, for example, the formula would output 13 since only one Stadium #3 is recorded.
I would change the values in the formula manually depending on what stadium number I'm looking for (i.e. 6 or 3) or what item I am looking for (i.e Boost or Glide).
The reason that the formula needs to be set up this way is because data will be continually entered into this spreadsheet and that data entry will never be finished.
I figure that this might involve the OFFSET and AVERAGE functions but I have no idea what else this would involve. This is where I need your help!
Please consider the following solution:
=AVERAGE(IF(B21:G21=6,INDIRECT("B"&MATCH("Boost",A:A,0)&":G"&MATCH("Boost",A:A,0)),""))
Inputted as an array formula using CTRL + SHIFT + ENTER. Explaining the logic first in the indirect; it finds the row matching column A to the item you want to report on (ie Boost or Glide). With the row it creates a range in the indirect referencing the row you want values for. It then generates an array with only the values for the columns of the stadium (6 in this case) by comparing the array of the same dimension formed from the Stadium row to your target stadium. Lastly it takes the average of the resulting array to output the expected answer. Regards,

If, Then, Duplicate Excel Formula

Column "A" is a numbering column for each Row, some numbers are the same, ie..
A1 is 1
A2 is 3
A3 is 1
A4 is 3
I need a formula that will show how many cells with content are in this column without counting duplicates, as above would be 2. I was figuring an "If-Then" formula but am unable to get it straight. Any help out there? Thank you in advance!
If you're using Excel 2013, I want to say that there's a count distinct function. Nonetheless, you can do it like this:
=SUM(IF(FREQUENCY(A1:A4,A1:A4)>0,1))
EDIT: Adding an explanation. The FREQUENCY function gets the frequency of the unique values within the array A1:A4 (first parameter), binning it using the values within A1:A4 (second parameter). The IF checks to see if that returns anything, i.e. if the frequency is greater than 0, in which case it returns 1 for each unique value it finds. Then the SUM adds the number of 1s returned by the IF statement, in turn giving you the number of unique values within the array A1:A4.

Resources