Need help with formula Rank and CountIF to decline the previous value

jamilm

Well-known Member
Joined
Jul 21, 2011
Messages
740
Gurus,

there might be a very simple solution but looks very tricky.

please see the attached file https://app.box.com/s/o8elz68uudeszbjj5jrm

I have names in the Column A and then the Registration Sequence in column B which is always numbers. in column C i have extracted values from SQL and and since these values are wrong becuase it does not decline the previous registration seq amount. so what i need is that on the next sequence for the same person, it must decline the previous amount and only put the difference either increase or decrese from the previous value. please see the excel file and the desired value column. please let me know, if this is unclear and further elaboration is needed.

thank you very much for your help as usual.



Excel 2010
ABCDEFG
1Person NameRegistration SequenceValueDesired ValueRank function
2James1210$21,140,0254th Smallest seq for Jamesfor 4th deduct the from previous one see formula$27,7904
3James1215$21,146,7355th Smallest seq for Jamessimilar as others deduct the previous smallest$6,7105
4James1134$21,107,4452nd smallest seq for Jamesfor second smallest decline meaning deduct the previous amount in first smallest$5,2102
5James1199$21,112,2353rd smallest seq for Jamesfor the third next smallest decline the previous one meaning deduct from 2nd$4,7903
6James1123$21,102,2351st smallest seq for Jamesfirst smallest return the whole amount$21,102,2351
7Sub total$105,608,675$21,146,735
8Richard1652$881,243$881,2431
9Richard1687$1,492,078$610,8352
10Sub total$2,373,321$1,492,078
11Robert469$1,055,874$1,055,8741
12Robert3011$1,082,895$8,0004
13Robert1976$1,057,418$1,5442
14Robert2939$1,074,895$17,4773
15Robert3359$1,083,740$8455
16Robert3646$1,083,240($500)6
17Sub total$6,438,062$1,083,240
Sheet1
Cell Formulas
RangeFormula
C7=SUM(C2:C6)
C10=SUM(C8:C9)
C17=SUM(C11:C16)
G8=RANK(B8,$B$8:$B$9,1)
G9=RANK(B9,$B$8:$B$9,1)
G11=RANK(B11,$B$11:$B$16,1)
G12=RANK(B12,$B$11:$B$16,1)
G13=RANK(B13,$B$11:$B$16,1)
G14=RANK(B14,$B$11:$B$16,1)
G15=RANK(B15,$B$11:$B$16,1)
G16=RANK(B16,$B$11:$B$16,1)
G2=RANK(B2,$B$2:$B$6,1)
G3=RANK(B3,$B$2:$B$6,1)
G4=RANK(B4,$B$2:$B$6,1)
G5=RANK(B5,$B$2:$B$6,1)
G6=RANK(B6,$B$2:$B$6,1)
F2=C2-C5
F3=C3-C2
F4=C4-C6
F5=C5-C4
F6=C6
F7=SUM(F2:F6)
F8=C8
F9=C9-C8
F10=SUM(F8:F9)
F11=C11
F12=C12-C14
F13=C13-C11
F14=C14-C13
F15=C15-C12
F16=C16-C15
F17=SUM(F11:F16)
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Is this sufficient for your needs?
Both formulas copied down.

Excel Workbook
ABCDEFG
1Person NameRegistration SequenceValueDesired ValueRank function
2James1210$21,140,025$27,790James|4
3James1215$21,146,735$6,710James|5
4James1134$21,107,445$5,210James|2
5James1199$21,112,235$4,790James|3
6James1123$21,102,235$21,102,235James|1
7Sub total$105,608,675$21,146,735
8Richard1652$881,243$881,243Richard|1
9Richard1687$1,492,078$610,835Richard|2
10Sub total$2,373,321$1,492,078
11Robert469$1,055,874$1,055,874Robert|1
12Robert3011$1,082,895$8,000Robert|4
13Robert1976$1,057,418$1,544Robert|2
14Robert2939$1,074,895$17,477Robert|3
15Robert3359$1,083,740$845Robert|5
16Robert3646$1,083,240($500)Robert|6
17Sub total$6,438,062$1,083,240
Rank & Diff
 
Upvote 0
Dear Peter,

this is perfect and works perfectly. thanks a billion. very much appreciated.

just one more thing. i do not need the rank column of G. can somehow we merge this two formula in one so that i only put the formula in F column and i would get my result?

i also do not need subtotals. the reason i previously put column G and subtotal. so that it would make my question clear in forum. otherwise my actual data is just like this shown in screenshot below.


Excel 2010
ABCD
1Person NameRegistration SequenceValueDesired Value
2James1210$21,140,025$27,790
3James1215$21,146,735$6,710
4James1134$21,107,445$5,210
5James1199$21,112,235$4,790
6James1123$21,102,235$21,102,235
7Richard1652$881,243$881,243
8Richard1687$1,492,078$610,835
9Robert469$1,055,874$1,055,874
10Robert3011$1,082,895$8,000
11Robert1976$1,057,418$1,544
12Robert2939$1,074,895$17,477
13Robert3359$1,083,740$845
14Robert3646$1,083,240($500)
Sheet1




Is this sufficient for your needs?
Both formulas copied down.

Rank & Diff

*ABCDEFG
1Person NameRegistration SequenceValue**Desired ValueRank function
2James1210$21,140,025 **$27,790 James|4
3James1215$21,146,735 **$6,710 James|5
4James1134$21,107,445 **$5,210 James|2
5James1199$21,112,235 **$4,790 James|3
6James1123$21,102,235 **$21,102,235 James|1
7Sub total*$105,608,675 **$21,146,735 *
8Richard1652$881,243 **$881,243 Richard|1
9Richard1687$1,492,078 **$610,835 Richard|2
10Sub total*$2,373,321 **$1,492,078 *
11Robert469$1,055,874 **$1,055,874 Robert|1
12Robert3011$1,082,895 **$8,000 Robert|4
13Robert1976$1,057,418 **$1,544 Robert|2
14Robert2939$1,074,895 **$17,477 Robert|3
15Robert3359$1,083,740 **$845 Robert|5
16Robert3646$1,083,240 **($500)Robert|6
17Sub total*$6,438,062 **$1,083,240 *

<colgroup><col style="width: 30px; font-weight: bold;"><col style="width: 106px;"><col style="width: 155px;"><col style="width: 105px;"><col style="width: 25px;"><col style="width: 26px;"><col style="width: 112px;"><col style="width: 112px;"></colgroup><tbody>
</tbody>

Spreadsheet Formulas
CellFormula
F2=IF(G2="",SUMIF(A$1:A1,A1,F$1:F1),C2-IF(RIGHT(G2,2)="|1",0,INDEX(C$2:C$17,MATCH(A2&"|"&REPLACE(G2,1,FIND("|",G2),"")-1,G$2:G$17,0))))
G2=IF(A2="Sub Total","",A2&"|"&SUMPRODUCT((A$2:A$17=A2)*(B2>B$2:B$17))+1)

<tbody>
</tbody>

<tbody>
</tbody>


Excel tables to the web >> Excel Jeanie HTML 4
 
Upvote 0
i do not need the rank column of G. can somehow we merge this two formula in one so that i only put the formula in F column and i would get my result?

i also do not need subtotals.
It can be done without the helper column - see my formula in D2 below. However, this is an array formula so should be entered without the {} but confirmed with Ctrl+Shift+Enter, not just Enter. If confirmed correctly, Excel will insert the {}. The formula can then be copied down. Array formulas tend to use more resources than standard formulas and if you edit them you have to remember to re-commit them with Ctrl+Shift+Enter.

An alternative would be to use the helper column, thereby keeping the formulas a little more straight-forward, and just hide the helper column after you have populated it with the formulas. If considering this approach I have posted the modified formula to leave out the subtotals.

Excel Workbook
ABCDEFG
1Person NameRegistration SequenceValueDesired ValueDesired ValueRank function
2James1210$21,140,025$27,790$27,790James|4
3James1215$21,146,735$6,710$6,710James|5
4James1134$21,107,445$5,210$5,210James|2
5James1199$21,112,235$4,790$4,790James|3
6James1123$21,102,235$21,102,235$21,102,235James|1
7Sub total$105,608,675
8Richard1652$881,243$881,243$881,243Richard|1
9Richard1687$1,492,078$610,835$610,835Richard|2
10Sub total$2,373,321
11Robert469$1,055,874$1,055,874$1,055,874Robert|1
12Robert3011$1,082,895$8,000$8,000Robert|4
13Robert1976$1,057,418$1,544$1,544Robert|2
14Robert2939$1,074,895$17,477$17,477Robert|3
15Robert3359$1,083,740$845$845Robert|5
16Robert3646$1,083,240($500)($500)Robert|6
17Sub total$6,438,062
Rank & Diff





BTW, best not to fully quote full posts, especially if you are not referring to anything specific in them, as it makes the thread harder to read/navigate and just occupies storage space needlessly. If you want to quote, quote small, relevant parts only.
 
Last edited:
Upvote 0
OK. understood. will not qoute full posts.

BTW, best not to fully quote full posts, especially if you are not referring to anything specific in them, as it makes the thread harder to read/navigate and just occupies storage space needlessly. If you want to quote, quote small, relevant parts only.
 
Upvote 0
Peter, thanks very much i liked the updated array formula =IF(A2="Sub Total","",C2-IFERROR(INDEX(C$2:C$17,MATCH(MAX(IF(A$2:A$17=A2,IF(B$2:B$17<B2,B$2:B$17))),IF(A$2:A$17=A2,B$2:B$17),0)),0))

although, i finished watching Mike's DVD videos CONTROL SHIFT ENTER which is very good tutorials of Array Formula. but still i could not figure out this sophisticated formula as you did.

I owe you a bottle of champagne.
 
Upvote 0
Reconsidering, since you appear to be using Excel 2010 you could use this normal entry formula directly ..

Excel Workbook
ABCD
1Person NameRegistration SequenceValueDesired Value
2James1210$21,140,025$27,790
3James1215$21,146,735$6,710
4James1134$21,107,445$5,210
5James1199$21,112,235$4,790
6James1123$21,102,235$21,102,235
7Sub total$105,608,675
8Richard1652$881,243$881,243
9Richard1687$1,492,078$610,835
10Sub total$2,373,321
11Robert469$1,055,874$1,055,874
12Robert3011$1,082,895$8,000
13Robert1976$1,057,418$1,544
14Robert2939$1,074,895$17,477
15Robert3359$1,083,740$845
16Robert3646$1,083,240($500)
17Sub total$6,438,062
Rank & Diff
 
Upvote 0

Forum statistics

Threads
1,215,125
Messages
6,123,193
Members
449,090
Latest member
bes000

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top