# Transform a column in a Perspective table

**URL:** <https://forum.inductiveautomation.com/t/transform-a-column-in-a-perspective-table/32617>\
**Category:** Ignition\
**Created:** [February 26, 2020, 9:34am UTC](https://forum.inductiveautomation.com/t/transform-a-column-in-a-perspective-table/32617 "2020-02-26T09:34:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![winbetho](https://avatars.discourse-cdn.com/v4/letter/w/ac91a4/32.png) [@winbetho](https://forum.inductiveautomation.com/u/winbetho)\
**Post date:** [February 26, 2020, 9:34am UTC](https://forum.inductiveautomation.com/t/transform-a-column-in-a-perspective-table/32617/1 "2020-02-26T09:34:47Z")

</div>

Hi all!

In Perspective, how do I transform a value to a string in a table?  
So the 0 will be “Bad” etc etc.

I basicly know how to use the transform binding but i don’t understand how to pass the correct value to the transform.

---

<div class="post-metadata">

**Author:** ![kirsten.chambers](https://avatars.discourse-cdn.com/v4/letter/k/48db29/32.png) [@kirsten.chambers](https://forum.inductiveautomation.com/u/kirsten.chambers)\
**Post date:** [February 26, 2020, 3:13pm UTC](https://forum.inductiveautomation.com/t/transform-a-column-in-a-perspective-table/32617/2 "2020-02-26T15:13:56Z")

</div>

There are actually a couple ways to go about this. Assuming you’re using a query binding to populate your table, you could utilize a ‘case’ expression in your query to map the values of a column to strings. This saves you some scripting if you’re more comfortable with your database. Stackoverflow with example [here.](https://stackoverflow.com/questions/38567366/mapping-values-in-sql-select/38567424)

If you want to go the script transform route, here’s a way to do so. I prefer the json return format for query bindings since it’s easy to dig into in Python.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/7/786159d26d2be84a4ad020bc9268ebbdc7746232.png)

Add a script transform. From there, accessing and altering the data is pretty simple; you can iterate through each row in your dataset and apply logic to each row as needed. You also can’t write back into `value`, so you’ll have to recreate your dataset (as far as I am aware).

```auto
# map out your numbers to your strings. dict is the pythonic way to do so
statusCodes = {0:"Bad", 1:"Good"} # etc.

# transformed dataset that will be returned at the end
newDataset = []

# iterate rows
for row in value: # value is the dataset passed into the transform from binding
    
    # create new row for newDataset
    newRow = {} 
   
    # iterate columns in each row
    for col in row:
        newColValue = row[col] # get each column's value
        if col == "Status": # or w/e the name of the column you want to transform is
            newColValue = statusCodes[newColValue] # change value into status code
        # if there are other columns you want to change values for,
        # you can add additional 'elif' statements after this 'if'
        
        # add data to our new row
        newRow[col] = newColValue
    
    # add the newly created row to the new dataset and start the loop again for next row
    newDataset.append(newRow)

return newDataset

```

Hope this helps!

---

<div class="post-metadata">

**Author:** ![winbetho](https://avatars.discourse-cdn.com/v4/letter/w/ac91a4/32.png) [@winbetho](https://forum.inductiveautomation.com/u/winbetho)\
**Post date:** [March 2, 2020, 11:34am UTC](https://forum.inductiveautomation.com/t/transform-a-column-in-a-perspective-table/32617/3 "2020-03-02T11:34:39Z")

</div>

Thanks! I changed the query, lots easier than the code.
