SOLVED

Function help for using iteration and circular reference

%3CLINGO-SUB%20id%3D%22lingo-sub-1414078%22%20slang%3D%22en-US%22%3EFunction%20help%20for%20using%20iteration%20and%20circular%20reference%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1414078%22%20slang%3D%22en-US%22%3E%3CP%3EI%20have%20a%20problem%20that%20I%20believe%20requires%20a%20circular%20reference.%20I%20would%20like%20to%20stop%20the%20iteration%20by%20copying%20a%20value%20only%20to%20a%20cell%20thus%20replacing%20the%20formula%20with%20the%20value.%20Is%20there%20a%20function%20that%20can%20help%20me%20do%20this%3F%3C%2FP%3E%3CP%3EThe%20algorithm%20is%3A%3C%2FP%3E%3CP%3ECalculate%20the%20values%20of%20the%20cells%20X3%2C%20Y3%2C%20and%20Z3.%26nbsp%3B%3C%2FP%3E%3CP%3E1.%20Find%20the%20row%20with%20the%20first%20zero%20in%20Column%20P.%3C%2FP%3E%3CP%3E2.%20Replace%20the%20formula%20in%20X3%20with%20the%20value%20in%20Column%20A%20of%20the%20row%20found.%3C%2FP%3E%3CP%3E3.%20Calculate%20the%20spreadsheet%20which%20will%20change%20the%20values%20in%20Column%20X%20and%20Column%20P.%3C%2FP%3E%3CP%3E4.%20Repeat%20for%20Y3%20and%20Z3.%20Iteration%20will%20stop%20when%20the%20formula%20in%20Z3%20has%20been%20replaced%20by%20a%20value.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAny%20ideas%20on%20how%20to%20do%20this%20with%20a%20formula%20and%20function%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1414078%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1414141%22%20slang%3D%22en-US%22%3ERe%3A%20Function%20help%20for%20using%20iteration%20and%20circular%20reference%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1414141%22%20slang%3D%22en-US%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F677914%22%20target%3D%22_blank%22%3E%40AshbyB%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIn%20my%20opinion%2C%20you%20might%20need%20to%20make%20use%20of%20macros.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1414747%22%20slang%3D%22en-US%22%3ERe%3A%20Function%20help%20for%20using%20iteration%20and%20circular%20reference%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1414747%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F677914%22%20target%3D%22_blank%22%3E%40AshbyB%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYes%2C%20you%20can%20do%20that%20also%20with%20formulas%20(if%20you%20don't%20want%20to%20use%20macros)%2C%20i.e.%2C%20you%20can%20make%20a%20formula%20in%20a%20cell%20reference%20itself%20(the%20same%20cell%20where%20the%20formula%20resides)%20and%20check%20its%20value%20against%20some%20starting%20default%20of%20your%20choosing%2C%20for%20instance%20check%20if%20it's%20zero%20and%20if%20it%20is%2C%20then%20return%20some%20other%20value%2C%20but%20if%20it's%20not%20zero%2C%20return%20the%20existing%20value%20-%20this%20way%20the%20initial%20value%20gets%20calculated%20only%20once%20and%20never%20changes%20thereafter.%3C%2FP%3E%3CP%3EThat's%20circular%20reference.%20To%20enable%20that%2C%20you%20go%3A%20Excel%26gt%3BOptions%26gt%3BFormulas%26gt%3BEnable%20iterative%20calculation%3A%3C%2FP%3E%3CDIV%20class%3D%22mceNonEditable%20lia-copypaste-placeholder%22%3E%26nbsp%3B%3C%2FDIV%3E%3CP%3Ein%20X3%3DIF(X3%3D0%2CYourLookedUpValFromCol_AWherCOlPEquals0%2CX3)%20%26lt%3B%26lt%3B%20so%2C%20this%20checks%20if%20the%20value%20in%20X3%20is%20zero%2C%20if%20it%20is%20-%20return%20the%20looked%20up%20value%2C%20if%20it%20is%20not%20zero%20-%20return%20current%20value%3C%2FP%3E%3CP%3Ein%20Y3%3DIF(AND(Y3%3D0%2CX3%26lt%3B%26gt%3B0)%2CYourLookedUpValFromCol_AWherCOlPEquals0%2CY3)%20%26lt%3B%26lt%3B%20so%2C%20this%20again%20check%20the%20current%20value%20in%20the%20Y3%20itself%20but%20it%20also%20checks%20the%20X3%20too%2C%20i.e.%2C%20this%20will%20return%20(and%20retain)%20the%20looked%20up%20value%20if%20the%20X3%20had%20already%20done%20that%3C%2FP%3E%3CP%3Ein%20Z3%3DIF(AND(Z3%3D0%2CY3%26lt%3B%26gt%3B0)%2CYourLookedUpValFrom_A_wherPeq0%2CZ3)%20%26lt%3B%26lt%3B%20similar%20to%20the%20Y3%20above.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1416735%22%20slang%3D%22en-US%22%3ERe%3A%20Function%20help%20for%20using%20iteration%20and%20circular%20reference%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1416735%22%20slang%3D%22en-US%22%3EThank%20you%20for%20your%20response.%20I%20will%20try%20the%20macro%20approach%20if%20a%20circular%20formula%20does%20not%20work.%3C%2FLINGO-BODY%3E
Highlighted
New Contributor

I have a problem that I believe requires a circular reference. I would like to stop the iteration by copying a value only to a cell thus replacing the formula with the value. Is there a function that can help me do this?

The algorithm is:

Calculate the values of the cells X3, Y3, and Z3. 

1. Find the row with the first zero in Column P.

2. Replace the formula in X3 with the value in Column A of the row found.

3. Calculate the spreadsheet which will change the values in Column X and Column P.

4. Repeat for Y3 and Z3. Iteration will stop when the formula in Z3 has been replaced by a value.

 

Any ideas on how to do this with a formula and function?

3 Replies
Highlighted

Hi @AshbyB 

 

In my opinion, you might need to make use of macros.

Highlighted
Solution

@AshbyB 

Yes, you can do that also with formulas (if you don't want to use macros), i.e., you can make a formula in a cell reference itself (the same cell where the formula resides) and check its value against some starting default of your choosing, for instance check if it's zero and if it is, then return some other value, but if it's not zero, return the existing value - this way the initial value gets calculated only once and never changes thereafter.

That's circular reference. To enable that, you go: Excel>Options>Formulas>Enable iterative calculation:

 

in X3=IF(X3=0,YourLookedUpValFromCol_AWherCOlPEquals0,X3) << so, this checks if the value in X3 is zero, if it is - return the looked up value, if it is not zero - return current value

in Y3=IF(AND(Y3=0,X3<>0),YourLookedUpValFromCol_AWherCOlPEquals0,Y3) << so, this again check the current value in the Y3 itself but it also checks the X3 too, i.e., this will return (and retain) the looked up value if the X3 had already done that

in Z3=IF(AND(Z3=0,Y3<>0),YourLookedUpValFrom_A_wherPeq0,Z3) << similar to the Y3 above.

Highlighted
Thank you for your response. I will try the macro approach if a circular formula does not work.