I need to iterate through field(column) names in a table and change them.

446
5
Jump to solution
07-30-2020 09:40 PM
DanielAmrine
Occasional Contributor

I used pivot table to place dates as individual fields(columns) but pivot table attaches the name of the original 

field to each new pivoted column. 

There are hundreds of these columns and i need can't change the name one by one.

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
JoeBorgione
MVP Esteemed Contributor

What do you want to change them to?  Is it a matter of slicing up the existing name and using just part of it for the new name? As David Pike‌ suggests, a little more jnfo to your end game would be helpful. 

You might consider looping through a list of field names and then use alter fields to make the changes.

That should just about do it....

View solution in original post

5 Replies
DavidPike
MVP Frequent Contributor

I'm unsure of what you want to do exactly.

DanielAmrine
Occasional Contributor

sorry about that, I guess the best way to describe it is to generate the list of field names and then strip them down to dates only, or at least shorter. 

0 Kudos
JoeBorgione
MVP Esteemed Contributor

What do you want to change them to?  Is it a matter of slicing up the existing name and using just part of it for the new name? As David Pike‌ suggests, a little more jnfo to your end game would be helpful. 

You might consider looping through a list of field names and then use alter fields to make the changes.

That should just about do it....
DanielAmrine
Occasional Contributor

Thank you Joe, I will test this today. I couldn't remember how to make the list. 

0 Kudos
JoeBorgione
MVP Esteemed Contributor

You'll need to be careful with the way you end up with a field name.  If all you want is the date, for example '1/1/'000' you can easily split the field name at the word 'date' and get the slice you want:

fieldName = 'Monthly_Production_Date1/1/2000'
justTheDate = fieldName.split('Date')[1]

''' justTheDate = '1/1/2000' '''

You've got two things working against you though:

1: Field names can't begin with a number

2: I'm not sure that a field name can contain a special character as a fore slash

That should just about do it....
0 Kudos