cancel
Showing results for 
Search instead for 
Did you mean: 

FOR loop in script logic

Former Member
0 Kudos

Dear Gurus,

This is the logic I am working with:

*FOR %MONTH% = 2008.FEB,2008.MAR,2008.APR,2008.MAY,2008.JUN,2008.JUL,2008.AUG,2008.SEP

//CHECK IF THE VALUE OF THE ACCUMULATED DEPRECIATION IS GREATER THAN THE CAPITALIZED ASSET VALUE//

[ACCOUNT].[#AccumDepr] = (([ACCOUNT].[AccumDepr]+[ACCOUNT].[Depreciation])>[ACCOUNT].[EQUIPMENT1]? [ACCOUNT].[EQUIPMENT1] : ([ACCOUNT].[AccumDepr]+[ACCOUNT].[Depreciation]))

*NEXT

I am trying to execute the above script logic, but the system is throwing an error that says

"Duplicate formula found: [ACCOUNT].[#AccumDepr] = (([ACCOUNT].[AccumDepr]+......."

Any idea why this is happening?

Also, could you please suggest a better way of writing the above code?

Thanks,

Vijay.

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

Please use the IIF statement to determine the condition.

One more thing I noticed was for every month, you are using the same formula and the formula doesnt have any dependence on the time member. For example, if you want to use the depreciation of 2008.feb, then you should have the tuple as

([ACCOUNT].[Depreciation],[TIME].[2008.FEB])

Hope this give you an idea.

Former Member
0 Kudos

Nilanjan,

Thanks for your response.

I just want to clarify that in my case, the depreciation will be constant over the life of the asset. So, it doesn't really matter if I reference the month in the calculation, I think. This is my scenario.

Capitalize the asset - Jan

Book Value = 600

Life = 6 months

Depreciation = 100

Based on the above scenario, the Accumulated depreciation should increase every month by 100, until it reaches the book value of 600. Thereafter, it should remain constant @ 600. That is why, I was writing the logic.

For every month, I was using the # symbol to indicate to the system that this is the target member. Is that wrong?

Thanks in advance for your guidance.

Former Member
0 Kudos

Hi,

You are using the account depreciation in your calculation. Have you already calculated this? How are you calculating this account?

Former Member
0 Kudos

As a testing scenario, I have calculated the depreciation in a different part of the same logic. Here it is:

//This logic calculates the accumulated depreciation amount for the time period specified in the logic
//NOTE:  This logic is not very dynamic and is only valid for the accounts specified in the logic

//A FUTURE ENHANCEMENT TO THIS LOGIC WOULD BE TO MAKE THE "LIFE" OF THE ASSET A $DATAMANAGER VARIABLE$
//AND WRITE A CUSTOM SCRIPT LOGIC

//--------------------------------------------------------------------------------------------------------------------//
//--------------------------------------------------------------------------------------------------------------------//

//BEGIN SCRIPT LOGIC FILE//

//CONSTANTS
*XDIM_MEMBERSET CATEGORY=ACTUAL
*XDIM_MEMBERSET ACCOUNT=Depreciation,AccumDepr,NBV_EQUIPMENT1,EQUIPMENT1
*XDIM_MEMBERSET ENTITY=STORE1
*XDIM_MEMBERSET TIME=2008.JAN,2008.FEB,2008.MAR,2008.APR,2008.MAY,2008.JUN,2008.JUL,2008.AUG,2008.SEP


//------------------------------------------------------------//
//BEGIN: POPULATE NET BOOK VALUE FROM CAPITALIZED ASSET VALUE //
//------------------------------------------------------------//
*WHEN ACCOUNT
*IS EQUIPMENT1
	*WHEN TIME
	*IS 2008.JAN
		*REC(FACTOR=1,ACCOUNT="NBV_EQUIPMENT1")
	*ENDWHEN
*ENDWHEN
*COMMIT
//------------------------------------------------------------//
//END: POPULATE NET BOOK VALUE FROM CAPITALIZED ASSET VALUE   //
//------------------------------------------------------------//


//------------------------------//
//BEGIN: CALCULATE DEPRECIATION //
//------------------------------//
*WHEN ACCOUNT
*IS EQUIPMENT1
	*REC(EXPRESSION=(%VALUE%/6),ACCOUNT="Depreciation")
*ENDWHEN
*COMMIT
//------------------------------//
//END: CALCULATE DEPRECIATION   //
//------------------------------//


//-------------------------------------------------------------//
//BEGIN: CALCULATE ACCUMULATED DEPRECIATION AND NET BOOK VALUE //
//-------------------------------------------------------------//


*FOR %MONTH% = 2008.FEB,2008.MAR,2008.APR,2008.MAY,2008.JUN,2008.JUL,2008.AUG,2008.SEP

//CHECK IF THE VALUE OF THE ACCUMULATED DEPRECIATION IS GREATER THAN THE CAPITALIZED ASSET VALUE//

*WHEN CATEGORY
*IS ACTUAL
*REC(EXPRESSION=IIF((([ACCOUNT].[AccumDepr] + [ACCOUNT].[Depreciation])>[ACCOUNT].[EQUIPMENT1]), [ACCOUNT].[EQUIPMENT1], [ACCOUNT].[AccumDepr]+[ACCOUNT].[Depreciation]))
*ENDWHEN

*NEXT

//*FOR %MONTH% = 2008.FEB,2008.MAR,2008.APR,2008.MAY,2008.JUN,2008.JUL,2008.AUG,2008.SEP

//CHECK IF THE NET BOOK VALUE OF THE ASSET IS LESS THAN ZERO//

//*[ACCOUNT].[#NBV_EQUIPMENT1] = (([ACCOUNT].[NBV_EQUIPMENT1]-[ACCOUNT].[Depreciation])>0? ([ACCOUNT].[NBV_EQUIPMENT1]-[ACCOUNT].[Depreciation]) : 0)

//*NEXT

*COMMIT

//-------------------------------------------------------------//
//END: CALCULATE ACCUMULATED DEPRECIATION AND NET BOOK VALUE   //
//-------------------------------------------------------------//


//END SCRIPT LOGIC FILE//

Please let me know if there is a better way to write this code.

Thanks for all your help.