Change calculation method with first re-occurrence of a column value

z3r01

New Member
Joined
Apr 29, 2015
Messages
1
Hi community.

I need some directions to solve a specific issue I have. The calculations below are made by referencing multiple other Worksheets. Those hold dynamic tables or defined ranges of such tables. The tables are retrieved from within a SQL database. The layout of the Workbook I'm working on is the following;

PKIDChangeRateHTCHTCNVHTF1HSTASTTF2TCNVATCARateATCDTCFGCDGRRdfKWYearNV
9349.761,315.583.0""TextA190187TextB""3.51,431.81-404031.7501-1564028.918694%20120
99-19.292,020.805.0""TextC300300TextD""3.51,443.781204011.0000.56974098.223097%20120
121-42.551,480.153.5""TextE100102TextA""3.01,365.34404021.50001554070.912927%20120
1277.041,463.073.5""TextD201201TextF""4.01,550.76-404011.0000.5-1284032.409231%20120

<tbody>
</tbody>

Definitions and Functions:

Column A = Integer (Unique respectively Primary Key) function
Code:
=IFERROR(INDEX(PKID,ROWS('HistDB'!A$2:A2)),"")

Column B = Decimal[2] - function
Code:
=IF(F3="","",IF(AND(M3<0,N3<=SUM($S3+2),G3<H3,O3=1),SUM(P3*N3*(Q3-T3)),IF(AND(Q3<1,N3>SUM($S3+2),O3<=2),SUM(P3*N3*(Q3-T3)),SUM(S3*P3*(Q3-T3)))))

Column C = Decimal[2] - function
Code:
=IF(F3="","",HLOOKUP(F3,Rates,ROWS(F$1:F3),FALSE))

Column D = Decimal[1] - function
Code:
[COLOR=#FF8C00]=IF(F3="","",IF(E3="",HLOOKUP(F3,TC,2,FALSE),""))[/COLOR]

Column E = Decimal[1] - function
Code:
=IFERROR(IF(V3=0,HLOOKUP(F3,[COLOR=#FF8C00]TC[/COLOR],2,FALSE),1),"")

Column F = Varchar[25] - function
Code:
=IFERROR(INDEX([COLOR=#B22222]TF[/COLOR],ROWS('HistDB'!B$2:B2)),"")

Column G = Integer (variable) - function
Code:
=IFERROR(INDEX(HST,ROWS('HistDB'!D$2:D2)),"")

Column H = Integer (variable) - function
Code:
=IFERROR(INDEX(AST,ROWS('HistDB'!E$2:E2)),"")

Column I = Varchar[25] - function
Code:
=IFERROR(INDEX([COLOR=#B22222]AF[/COLOR],ROWS('HistDB'!E$2:E2)),"")

Column J = Decimal[1] - function
Code:
=IFERROR(IF(V3=0,HLOOKUP(I3,TC,2,FALSE),1),"")

Column K = Decimal[1] - function
Code:
[COLOR=#FF8C00]=IF(I3="","",IF(J3="",HLOOKUP(I3,TC,2,FALSE),""))[/COLOR]

Column L = Decimal[2] - function
Code:
=IF(I3="","",HLOOKUP(I3,Rates,ROWS(I$1:I3),FALSE))

Column M = Integer - function
Code:
=IF(F3="","",IF(E3="",IF(D3>K3,SUM(D3-K3)*80,SUM(D3-K3)*80),IF(E3>J3,SUM(E3-J3)*80,SUM(E3-J3)*80)))

Column N = Integer - function
Code:
=IFERROR(IF($M3=-160,SUM($S3+2),IF($M3=-200,SUM($S3+3),IF($M3=-240,SUM($S3+4),IF($M3=-280,SUM($S3+5),IF($M3=-320,SUM($S3+6), IF($M3=160,SUM($S3+7),IF($M3=200,SUM($S3+8),IF($M3=240,SUM($S3+9),IF($M3=280,SUM($S3+10),IF($M3=320,SUM($S3+11),SUM($S3))))))))))),"")

Column O = Integer - function
Code:
=IF(F3="","",IF(G3=H3,1,IF(G3>H3,SUM(G3-H3),SUM(H3-G3))))

Column P = Decimal[3] - function
Code:
=IF(F3="","",IF(O3=1,1,(IF(O3=2,1.5,SUM((11+O3)/8)))))

Column Q = Decimal[1] - function
Code:
=IF(F3="","",IF(G3=H3,0.5,IF(G3>H3,1,0)))

Column R = Integer - function
Code:
=IF(F3="","",C3-L3+M3)

Column S = Integer - function
Code:
=IFERROR(INDEX(KFactor,ROWS('HistDB'!G$2:G2)),"")

Column T = Decimal[6] - function
Code:
=IF(F3="","",SUM(1/(10^(-R3/400)+1)))

Column U = Date[4] - function
Code:
=IFERROR(INDEX(YearF,ROWS('HistDB'!L$2:L2)),"")

Column V = Boolean - function =IFERROR(INDEX(NVF,ROWS('HistDB'!H$2:H2)),1)


Now with the layout and definitions available, the description of what I need to achieve. Basically, whenever Column F[TF1] OR Column I[TF2] get their first re-occurrence within the dynamic range, the defined function to retrieve the value(s) within Column D[TCH] respectively Column K[TCA] should be looking up the changed value based on the above calculations. Therefore, the function;
Code:
=IF(F3="","",IF(E3="",HLOOKUP(F3,TC,2,FALSE),""))
needs another IF statement respectively a new table or defined range to retrieve the new value from.

Issue 1)

To get the 2nd occurrence of Column F[TF1] I could use the following function;

Code:
=INDEX(CGCalc[PKID],SMALL(IF(Range=CGCalc[@[TF]],ROW(Range)-2,""),2),1)

However, if the re-occurrence happens within TF2 the above function changes to;

Code:
=INDEX(CGCalc[PKID],SMALL(IF(Range=CGCalc[@[AF]],ROW(Range)-2,""),2),1)

a) is there a (easier/better) way to retrieve the position of the re-occurrence and b) possibly in one step (regardless if the occurrence happens either in TF1 or TF2)?

Issue 2)

Now the part where it gets really dirty. After calculating the first, and only the first re-occurrence (there can be many more afterwards), the calculations within Column D[TCH] respectively Column K[TCA] must be changed to reflect the fact that from now on the value(s) to be retrieved into Columns D respectively Column K aren't anymore in the defined range [TF and/or AF] used within the Column D and K functions. The two ranges TF and AF are holding a defined range with unique text values TF1 and TF2 and the initial integers TC used within the functions in Columns D and K.

So, the "orange" marked code will and must change. Of course, based on that change many other values and calculations are affected. The colors navy blue respectively green indicate the Columns/Functions to be changed. The red color indicates the two defined ranges which are now used to retrieve the initial values to allow the calculations within Column D respectively Column K.

I hope I explained everything understandable enough, if not just shoot with questions. I will be grateful for any help anyone can provide.
 

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.

Forum statistics

Threads
1,214,904
Messages
6,122,169
Members
449,070
Latest member
webster33

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