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

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
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
Person Name**
James**
James**
James**
James**
James**
Sub total****
Richard**
Richard**
Sub total****
Robert**
Robert**
Robert**
Robert**
Robert**
Robert**
Sub total****

<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>
[TD="bgcolor: #CACACA, align: center"]1[/TD]

[TD="align: right"]Registration Sequence[/TD]
[TD="align: right"]Value[/TD]

[TD="align: right"]Desired Value[/TD]
[TD="align: center"]Rank function[/TD]

[TD="bgcolor: #CACACA, align: center"]2[/TD]

[TD="align: right"]1210[/TD]
[TD="align: right"]$21,140,025 [/TD]

[TD="align: right"]$27,790 [/TD]
[TD="align: center"]James|4[/TD]

[TD="bgcolor: #CACACA, align: center"]3[/TD]

[TD="align: right"]1215[/TD]
[TD="align: right"]$21,146,735 [/TD]

[TD="align: right"]$6,710 [/TD]
[TD="align: center"]James|5[/TD]

[TD="bgcolor: #CACACA, align: center"]4[/TD]

[TD="align: right"]1134[/TD]
[TD="align: right"]$21,107,445 [/TD]

[TD="align: right"]$5,210 [/TD]
[TD="align: center"]James|2[/TD]

[TD="bgcolor: #CACACA, align: center"]5[/TD]

[TD="align: right"]1199[/TD]
[TD="align: right"]$21,112,235 [/TD]

[TD="align: right"]$4,790 [/TD]
[TD="align: center"]James|3[/TD]

[TD="bgcolor: #CACACA, align: center"]6[/TD]

[TD="align: right"]1123[/TD]
[TD="align: right"]$21,102,235 [/TD]

[TD="align: right"]$21,102,235 [/TD]
[TD="align: center"]James|1[/TD]

[TD="bgcolor: #CACACA, align: center"]7[/TD]

[TD="align: right"]$105,608,675 [/TD]

[TD="align: right"]$21,146,735 [/TD]

[TD="bgcolor: #CACACA, align: center"]8[/TD]

[TD="align: right"]1652[/TD]
[TD="align: right"]$881,243 [/TD]

[TD="align: right"]$881,243 [/TD]
[TD="align: center"]Richard|1[/TD]

[TD="bgcolor: #CACACA, align: center"]9[/TD]

[TD="align: right"]1687[/TD]
[TD="align: right"]$1,492,078 [/TD]

[TD="align: right"]$610,835 [/TD]
[TD="align: center"]Richard|2[/TD]

[TD="bgcolor: #CACACA, align: center"]10[/TD]

[TD="align: right"]$2,373,321 [/TD]

[TD="align: right"]$1,492,078 [/TD]

[TD="bgcolor: #CACACA, align: center"]11[/TD]

[TD="align: right"]469[/TD]
[TD="align: right"]$1,055,874 [/TD]

[TD="align: right"]$1,055,874 [/TD]
[TD="align: center"]Robert|1[/TD]

[TD="bgcolor: #CACACA, align: center"]12[/TD]

[TD="align: right"]3011[/TD]
[TD="align: right"]$1,082,895 [/TD]

[TD="align: right"]$8,000 [/TD]
[TD="align: center"]Robert|4[/TD]

[TD="bgcolor: #CACACA, align: center"]13[/TD]

[TD="align: right"]1976[/TD]
[TD="align: right"]$1,057,418 [/TD]

[TD="align: right"]$1,544 [/TD]
[TD="align: center"]Robert|2[/TD]

[TD="bgcolor: #CACACA, align: center"]14[/TD]

[TD="align: right"]2939[/TD]
[TD="align: right"]$1,074,895 [/TD]

[TD="align: right"]$17,477 [/TD]
[TD="align: center"]Robert|3[/TD]

[TD="bgcolor: #CACACA, align: center"]15[/TD]

[TD="align: right"]3359[/TD]
[TD="align: right"]$1,083,740 [/TD]

[TD="align: right"]$845 [/TD]
[TD="align: center"]Robert|5[/TD]

[TD="bgcolor: #CACACA, align: center"]16[/TD]

[TD="align: right"]3646[/TD]
[TD="align: right"]$1,083,240 [/TD]

[TD="align: right"]($500)[/TD]
[TD="align: center"]Robert|6[/TD]

[TD="bgcolor: #CACACA, align: center"]17[/TD]

[TD="align: right"]$6,438,062 [/TD]

[TD="align: right"]$1,083,240 [/TD]

</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,223,236
Messages
6,170,917
Members
452,366
Latest member
TePunaBloke

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