Dec 13 2021 03:07 PM
Hi experts
Can you help me with the below?
I have a list of cash values in a table, example as follows by a rotating week number (1-4).
A ------------ B
1 ----------- 40
2------------- 30
3------------ 22
4 -----------56
1 -----------33
2 -----------15
3 -----------9
4------------40
1------------18
2------------79
3------------45
4------------61
What I want to do is have a formula to always pick out the second to last value corresponding to the week number. For example if I wanted the second to last value of week 4....
The formula would spit out = 40
If I wanted the second to last value of week 2....
The formula would spit out = 15
I have a formula to get the last value for each week... but second to last I am struggling with. I also need to mention the formula must ignore blank values!!!
Any help appreciated
Matt
Dec 13 2021 03:44 PM
=INDEX($B$1:$B$12,LARGE(IF(($A$1:$A$12=$D$1)*($B$1:$B$12<>""),ROW($1:$12)),2))
Is this what you are looking for? If you don't work with Office365 or 2021 you have to enter formula as arrayformula with ctrl+shift+enter.
Dec 14 2021 12:57 AM
Thanks so much for your reply. Sadly haven't got it to work like in your example.
I have knocked up an example spreadsheet. Hopefully this makes sense on how I am trying to use a formula for the second to last value in list?
I also have a formula for last value, this works fine as you will see.
Can you take a look and see what I mean from the cells highlighted in yellow?
Thank you again
Dec 14 2021 04:20 AM
Use
=INDEX($C$6:$C$58,LARGE(IF(($A$6:$A$58=F5)*($C$6:$C$58<>"")*($B$6:$B$58=G5),ROW($C6:$C58)-ROW($C$6)+1),2))
or
=INDEX($C$6:$C$58,LARGE(($A$6:$A$58=F5)*($B$6:$B$58=G5)*($C$6:$C$58<>"")*(ROW($C$6:$C$58)-ROW($C$6)+1),2))
If you don't have Office 2021 or Microsoft 365, confirm with Ctrl+Shift+Enter.
Dec 14 2021 08:52 AM
Dec 14 2021 09:15 AM
You'll have to adjust the formula for the actual range of course.
If that doesn't work for you, please attach a workbook that better represents your real setup.
Dec 14 2021 09:27 AM
Just in case, this one doesn't require CSE if you are not on Excel 365/2021
=INDEX( $C$6:$C$58, AGGREGATE(14, 6, 1/($A$6:$A$58=$F$5) / ($C$6:$C$58 <> "") *(ROW($A$6:$A$58) - ROW($A$5) ), $G$5 ) )
It's always better to mention Excel version.
Mar 11 2023 04:42 AM
I am getting #REF! error please help resolve @OliverScheurich
Mar 11 2023 07:22 AM
=INDEX($B$1:$B$12,LARGE(IF(($A$1:$A$12=D1)*($B$1:$B$12<>""),ROW($1:$12)),2))
Does this work in your sheet? Enter the formula as an arrayformula with ctrl+shift+enter if you don't work with Office 365 or Excel 2021.
Mar 11 2023 11:16 PM
downloaded your file, looking good but I am still getting #REF! error, could not attach my Excel file to this reply, please guide @OliverScheurich
Mar 12 2023 12:52 AM
You need to specify the Excel version. Otherwise you might get solutions like
= MAP({1;2;3;4},
LAMBDA(w,
LET(
criterion, (week=w)*(amount>0),
matches, FILTER(amount, criterion),
CHOOSEROWS(matches,-2)
)
)
)
A solution written for Excel 365 may have very little in common with earlier generations of spreadsheet.
Mar 12 2023 10:26 AM
In the screenshot below i've highlighted where you can attach either a file or a screenshot.
Mar 12 2023 01:29 PM
You can use the following formula to get the second to last value for a specific week number:
=INDEX(B:B,MAX(IF(A:A=week_number,ROW(B:B)-ROW(B1)+1)))
Replace week_number with the week number you're interested in.
This is an array formula that uses the INDEX and MAX functions. Here's how it works:
Make sure to enter this formula as an array formula by pressing Ctrl+Shift+Enter instead of just Enter. This will add curly braces around the formula in the formula bar to indicate that it's an array formula.
Mar 16 2023 11:10 PM
Mar 17 2023 08:10 AM
=INDEX(Z1412:Z1761,LARGE(IF((D1412:D1761=M1769)*(Z1412:Z1761<>""),ROW(1412:1761)-1411),2))
Does this return the expected result?
Mar 18 2023 04:58 AM - edited Mar 18 2023 05:35 AM
Thank you very much it is working fine. Can you please suggest a formula for last value based on criteria with if condition based on another column, which works on google sheet as you may know Google Sheet does not accept formula with Filter & Aggregate commands
Mar 18 2023 05:34 AM
=INDEX(Z1412:Z1761,LARGE(IF((D1412:D1761=M1769)*(Z1412:Z1761<>""),ROW(1412:1761)-1411),1))
Does this return the expected result? I only work with Excel and therefore can only suggest solutions for Excel.
Mar 18 2023 05:43 AM
Mar 18 2023 06:43 AM
Maybe i can help you with this. Which additional condition do you want and on which column should it be based?