Solved

Bulk Rename Attributes with Original Name plus the First Row


Can FME do a bulk rename of all attributes to combine the original name and the first row. See picture for example. The left side is the input. The right side is the desired output.

icon

Best answer by erik_jan 14 May 2020, 23:52

View original

4 replies

Userlevel 2
Badge +16

After reading the spreadsheet without field names (defaulting to the column names A and B), this workflow got me the right fields and values:

Sample the first to lines to create the field names.

Aggregate those to have the field names combined with the _.

Copy the names into new attributes.

Merge the new names on each data row.

Use an attribute creator to create the new fields with the right values.

 

Hope this helps.

After reading the spreadsheet without field names (defaulting to the column names A and B), this workflow got me the right fields and values:

Sample the first to lines to create the field names.

Aggregate those to have the field names combined with the _.

Copy the names into new attributes.

Merge the new names on each data row.

Use an attribute creator to create the new fields with the right values.

 

Hope this helps.

Your workbench does exactly what I asked. However, I should have mentioned that I have several (over 200) fields in the table and the solution above is just as time consuming at manually renaming all the fields.

Userlevel 3
Badge +17

Hi @excel_zm

You can try creating a lookup table and using this lookup table with the SchemaMapper to map the attribute names. You will have to create the lookup table first before setting up the SchemaMapper so you may want to separate creating the lookup table into another workspace.

Workbench won’t display these mapped attributes automatically. Since you mentioned you have many attributes, it may be easiest to skip exposing these attributes and use the SchemaSetter with a dynamic writer to write your output.

I have attached a workspace demonstrating the two steps mentioned above. schemamapperattributename.fmwt

Userlevel 3
Badge +17

Hi @excel_zm

You can try creating a lookup table and using this lookup table with the SchemaMapper to map the attribute names. You will have to create the lookup table first before setting up the SchemaMapper so you may want to separate creating the lookup table into another workspace.

Workbench won’t display these mapped attributes automatically. Since you mentioned you have many attributes, it may be easiest to skip exposing these attributes and use the SchemaSetter with a dynamic writer to write your output.

I have attached a workspace demonstrating the two steps mentioned above. schemamapperattributename.fmwt

Actually, if your destination format is Excel or CSV, you can also not write column names after aggregating the two header rows which should give the desired output. Much simpler than using a dynamic schema but only applicable to formats that allow not writing field names.

merge2headerrowsforexcel.fmwt

Reply