Excel formula to return last xth numeric value from row - excel

I have a data set like this:
a 1 2 3 5 6 7
b 5 1 3 4
c 7 4 3 2 6
d 1 2 3 7
e 7 5 5 6 7
which i want to transform in excel to only show the last 4 numeric values for each row, i.e.
a 3 5 6 7
b 5 1 3 4
c 4 3 2 6
d 1 2 3 7
e 5 5 6 7
Ive managed to use =INDEX(row1,MATCH(9.99999999999999E+307,row1)) which correctly returns the last value (i.e. 7 for row1 in this case) but how could i get the 2nd last, 3rd last, 4th last etc?

With a in A1, in M1 copied across and down to suit:
=MID(RIGHT($B1&$C1&$D1&$E1&$F1&$G1&$H1&$I1&$J1,4),COLUMN()-12,1)
then hide ColumnsB:L.
(Only works for single digits, as shown. Recent versions of Excel may offer better options.)

So I managed to figure out how to do this generically for any digits:
Say your original numerical data is in cells D5:N9.
OPTIONAL:
If any of the rows of data contain the same value twice create a copy in cells D13:N17 which amends duplicates slightly by using in D13 and dragging to fill
=IF(D5="","",D5+0.0001*(COUNTIF($D5:D5,D5)-1))
Then in cells A13:A17 enter values 13,14,15,16,17
and in cells A20:A29 enter values D, E, F, G, H, I, J, K, L, M
In Cell D20 you can return the last from row 13 value using:
=LOOKUP(9.99999999E+307,D13:N13)
and copy this down for each row.
In Cell E20 you can return the 2nd last entry using
=LOOKUP(9.99999999E+307,$D13:INDIRECT(CONCATENATE(INDEX($A$20:$A$29,MATCH(D20,$D13:$N13,0)-1),$A13)))
and copy this down for each row and drag it across to H24 to fill in all the values for 3rd last, 4th last and 5th last for each row.

Related

Increment value in Excel column depending on existing values in other column

I have 4 columns in Excel: A, B, C, and D. I want two of the columns (C & D) to auto-populate based on the input in the other two columns (A & B). The first column that auto-populates (C) should start at 1 and increment each time a new value is added in the same row of column B. Column D should also start at 1 and increment each time a new value is added in the same row of column B, however, if column A has the same value as the previous row (i.e., a date) then it should not increment but instead be the same value as column D in the previous row. Additionally, if a value in column B is repeated, but with a different value (i.e., a date) in column A, then it's corresponding value in column C should be the same as before, but the value in column D should still increment because the value in column A is new.
To visualize:
A B C D
Jan. 5 red 1 1
Jan. 5 gre 2 1
Jan. 6 pin 3 2
Jan. 6 pur 4 2
Jan. 7 bla 5 3
Jan. 7 blu 6 3
Jan. 8 red 1 4
Jan. 8 gre 2 4
Jan. 9 yel 7 5
Jan. 9 ora 8 5
I hope this makes sense. Any help would be greatly appreciated!
Assuming "A" is in cell A1, hardcode 1 in C2 and D2 then in C3 and downwards:
=iferror(index($C$2:$C2,match(B3,$B$2:$B2,0)),max($C$2:$C2)+1)
and in D3 and downwards:
=if(A3="","",if(A3=A2,D2,max($D$2:D2)+1))

Summing a set of values based on cell content and row position

In the below table rows 2,3 and 4 have some details of a sporting event.
Range A2:C4 has a set of squad numbers and range D2:F4 has the details of who scored goals.
A B C D E F
1 Squad # Scorers
2 1 3 6 2 8 3
3 3 6 7 6 1
4 1 5 6 7 2 4
As an example squad # 6 has scored 8 goals based on the values equivalent position in the Squad section and relative to the Scorers range.
What formula will give me this total value and the equivalent total values for all squad numbers like the table below?
Some cells will be empty like F3.
1 9
3 14
5 2
6 8
7 0
A simple SUMPRODUCT function should take care of this.
=SUMPRODUCT($D$2:$F$4, --($A$2:$C$4=H2))
Fill down as necessary.
        
With only 3 games, the simplest way that I can see to do this would be to use 4 SUMIFS statements, as follows [assumes that your results data is in columns A & B, starting at row 5 and moving down; A5:A12 would hold the IDs for the different squads, and this formula would go in B5 and be copied down]:
=SUMIFS($D$2:$F$2,$A$2:$C$2,A5)+SUMIFS($D$3:$F$3,$A$3:$C$3,A5)+SUMIFS($D$4:$F$4,$A$4:$C$4,A5)
What it does is sum columns D:F, for row 1, row 2, and row 3, based on the fact that columns A:C for those rows match the appropriate squad ID.
This would be possible with an arguably shorter but more complex Array Formula, but with the data as you've presented it, I feel this is the clearest method.

A function that will lookup a reference

Before I get started thanks for taking your time and helping.
This is what my worksheet looks like:
Row # B C D E F
2 1 Product 1 B2 B3 B4
3 2
4 6
5 1 Product 2 B5 B6
6 5
7 4 Product 3 B7
I was trying to follow this formula: (The best answer one or green check mark) return values from multiple matching rows
I got all the way to the =IFERROR(INDIRECT(lookups!H5),"") but can not get this to work.
What I am tying to do is order the numbers in Column B to go to the right of the product. Which I was able to get the column it is in (B) and the row number it is in (B2). I would like to change the value (B2) to the number that is there.
I would like it to look like this:
Row # C D E F
2 Product 1 1 2 6
3
4
5 Product 2 1 5
6
7 Product 3 4
If someone could help explain this to me or find a better way that would be great.
Not sure what is to happen to columnB but if you replace B with "="B throughout columns D:F then select each of these in turn and apply Text to Columns with Tab as the delimiter the 'cell references' convert to formulae referring to the values in B. If you want to delete columnB copy D:F and Paste Special, Values over the top.

Return list of matching rows

Sheet1
A B C D
1 2 3 4
2 4 5 6
3 3 5 6
4 7 3 1
5 4 6 7
Sheet 2
A B C D
1 4
2 1
3 1 3 4
4 1 2 5
5 2 3
6 2 3 5
7 4 5
Column A of Sheet 2 has a non repeating listing of all values in Sheet 1. I would like a forumla so Col B of Sheet 2 lists the value of Sheet 1 Col A for each row where the Sheet 2 Col A lookup value is found. Either giving me a comma sep list or putting the results in sheet 2 Col B,C,D,...
I came up with a solution, but it involves a handful of formulas, not just one. Hopefully, you will still find it useful.
Your Sheet2 would basically look like this:
Here are the formulas you need to enter:
B1: =IFERROR(SMALL($G4:$U4,COLUMN()-1),"") [drag down and across to D7]
G1: =IF(F2=$W2,F1+1,MAX(1,F1)) [drag across to U1]
G2: =IF(F2=$W2,1,F2+1) [drag across to U2]
G3: =INDEX(Sheet1!B$1:D$5,G1,G2) [drag across to U3]
G4: =IF(G$3=$F4,G$1,"") [drag down and across to U10]
What this does is organize the Sheet1 data into rows, where each row corresponds to a lookup value. Then, it grabs the smallest value, the second smallest value (if one exists), and third smallest value (if one exists) from each row.
This should be easy to scale to as large a spreadsheet as you need (as long as you don't run out of columns).

Compare two columns in excel

Hey, I have an excel document with columns A and B. Row A has 2595 values. Row B has 411 values.
I'm trying to figure out how I can compare these two columns by marking column C with the number of times we find a value(s) from row a.
For Example
COLUMN A COLUMN B COLUMN C
1 1 1 (because we have one value of 1 from column A)
2 2 1 (because we have one value of 2 from column A)
3 3 2 (because we have 2 threes from column A)
3 4
4 5
5 6 2 (because there are two 6's in column A)
6 7 0 (because there are no 7's in column A)
6
I'm sure you can see where I'm going with this but for the life of me I cannot figure out how to do this, I've been searching around all morning. Help!
If needed I can supply the excel document.
You can use the COUNTIF function
Column A Column B Column C Answer
1 1 =COUNTIF($A$2:$A$9,B2) [1]
2 2 =COUNTIF($A$2:$A$9,B3) [1]
3 3 =COUNTIF($A$2:$A$9,B4) [2]
3 5 =COUNTIF($A$2:$A$9,B5) [1]
4 6 =COUNTIF($A$2:$A$9,B6) [2]
5 7 =COUNTIF($A$2:$A$9,B7) [0]
6
6
You can use COUNTIF. If A1:A8 is your search criteria, B1 is the value you're currently processing, C1 would be:
=COUNTIF(A1:A8;B1)

Resources