Select to view content in your preferred language

Using Calculate Value with Table Iterator

2296
2
Jump to solution
09-11-2014 02:10 PM
PeninahMurage
Deactivated User

Is it also possible  to use Calculate Value with the Table Iterator? I have 9000 tables each with a column name that needs altering. So for example, all the tables have a column called 'Rastervalu', I would like to change this name for each column to represent a unique value which is the table name. So again in first table 'RasterValu' will be called 'GP-CodeA82010'.

 

As I am hoping to eventually join these tables to a master table. Using model builder I would like to truncate/drop the 'GP_Code' part of the name and leave the name as 'A82010' and so forth.

 

Am very new to Python but have tried different expressions as follows;

 

Right([FieldName], 6)

"%Name%"[7:13]

"%Name%".replace("GP_Code","")

 

However the Calculate Value model only tool does not appear to do the job, so instead of slicing the 'GP_Code' bit inorder to give me the reduced name, it is giving me a value of 1 (see attached image)

 

Any ideas of what I might be doing wrong? or what script I should be using?

 

Many thanks

Penny

0 Kudos
1 Solution

Accepted Solutions
RiyasDeen
Frequent Contributor

Hi Peninah,

"%Name%".replace("GP_Code",""), should have worked.

The thick line between your name and calculate value tells me, you are passing Name as expression and placed the code in code block.

You want to have your calculate value expression as shown in image below.

Also note the doted line, it means having value for Name parameter is a precondition for Calculate Value to execute and is not passed as expression to the tool.

Name parameter can be accessed across the model as %Name%, you don't have to pass it explicitly to the tool.

Untitled.png

View solution in original post

0 Kudos
2 Replies
RiyasDeen
Frequent Contributor

Hi Peninah,

"%Name%".replace("GP_Code",""), should have worked.

The thick line between your name and calculate value tells me, you are passing Name as expression and placed the code in code block.

You want to have your calculate value expression as shown in image below.

Also note the doted line, it means having value for Name parameter is a precondition for Calculate Value to execute and is not passed as expression to the tool.

Name parameter can be accessed across the model as %Name%, you don't have to pass it explicitly to the tool.

Untitled.png

0 Kudos
PeninahMurage
Deactivated User

That has fixed it. I thank you profusely Riyas.

0 Kudos