Names and Values
These types of files come up many times for many reasons, in fact I came across a file similar to this when scraping my IronViz. Here's an example of a file:![name-value](http://www.theinformationlab.co.uk/wp-content/uploads/2016/09/Name-Value.png)
![Key](http://www.theinformationlab.co.uk/wp-content/uploads/2016/09/2016-09-19_20-46-22.png)
Adding a Key
To add a key as above we need to use a formula like this:if [Name] ='Row ID' then [Row-1:Key]+1 else [Row-1:Key] endifDoing this can't be done via the normal formula tool though as it doesn't support looking back or forward across multiple rows. Instead you need the Multi-Row Formula in the Preparation Category (don't confuse it with the Multi-Field formula which runs the same formula on multiple columns).
![multi-row-formula](http://www.theinformationlab.co.uk/wp-content/uploads/2016/09/Multi-Row-Formula.png)
![configmr](http://www.theinformationlab.co.uk/wp-content/uploads/2016/09/ConfigMR.png)
CrossTab
Now we simply need to crosstab the data, we need to Group by the Key - grouping creates a new row per field selected. The Name field will become our headers and the Value Field will be our data.![configcrosstab](http://www.theinformationlab.co.uk/wp-content/uploads/2016/09/ConfigCrossTab-583x705.png)
![crosstabresult](http://www.theinformationlab.co.uk/wp-content/uploads/2016/09/CrosstabResult-705x258.png)
Final Bonus Section
If you were astute you'll have noticed that the Crosstab Tool takes non-alphanumeric characters and turns them into an underscore in the Column Names. How do you fix this? Well first we need to know the old name and the new name...so let's use a formula tool on a branch of our original data set.....REGEX_Replace([Name], '[^A-Z0-9]', '_')
This formula will create what I call [CT Name] the new CrossTab field name.
Finally let's rename the strings using the Dynamic Rename tool to rename the Crosstabbed headers back to the originals using this new data stream. Your module should look like this I moved the Auto Field until after the grey Dynamic Rename - there's no reason for this except the messages from the Auto Field will refer to real field names now):
The Dynamic Rename replaces the Field Headers in its Left (Top) Input with the Data from the rows in its Right (Bottom) Input - so the config for that tool looks something like this:
Note that I've chosen to 'Ignore' the number of Field Names not matching, I could easily have used a Unique tool to simply keep the distinct [Name].