# Mapping transform in Ignition Perspective

**URL:** <https://forum.inductiveautomation.com/t/mapping-transform-in-ignition-perspective/90991>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [May 28, 2024, 8:50am UTC](https://forum.inductiveautomation.com/t/mapping-transform-in-ignition-perspective/90991 "2024-05-28T08:50:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alejandro\_Alaco](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/alejandro_alaco/32/59849_2.png) [@Alejandro\_Alaco](https://forum.inductiveautomation.com/u/Alejandro_Alaco)\
**Post date:** [May 28, 2024, 8:50am UTC](https://forum.inductiveautomation.com/t/mapping-transform-in-ignition-perspective/90991/1 "2024-05-28T08:50:06Z")

</div>

Hello!

I´m trying to do a mapping transform so when my cell value "0" it appears empty instead.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/c/ec111f1ae2fb13c690b3dc39798f36ff334b51b3.png)

The orinal data comes from a Named Query.

But I getting this error when I do the mapping  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/0/5017ba8eea9ed87865a16c46f6583a054f69ee64.png)

I´m not sure this is the way to do things or would be better to apply a Transform Script.

Cheers.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [May 28, 2024, 8:58am UTC](https://forum.inductiveautomation.com/t/mapping-transform-in-ignition-perspective/90991/2 "2024-05-28T08:58:32Z")

</div>

Map tranforms can only transform a single value - not a list or table of values.

That means that it can only be used for a named query giving a **scalor** return value (just a single number, string or date).

You have three options (at least):

1. Modify your SQL to return the string. (Not the best idea.)
2. Use a script transform.
3. Create a lookup table with id and string columns and return those with a JOIN statement on the original named query.

---

<div class="post-metadata">

**Author:** ![Alejandro\_Alaco](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/alejandro_alaco/32/59849_2.png) [@Alejandro\_Alaco](https://forum.inductiveautomation.com/u/Alejandro_Alaco)\
**Post date:** [May 28, 2024, 1:41pm UTC](https://forum.inductiveautomation.com/t/mapping-transform-in-ignition-perspective/90991/3 "2024-05-28T13:41:11Z")

</div>

```python
def transform(self, value, quality, timestamp):	

	value_mapping = {
	    1: "Adecuado",
	    2: "Trivial",
	    3: "Tolerable",
	    4: "Moderado",
	    5: "Importante",
	    6: "Intolerable"
	}
	
	def transform_dataset(dataset):
	   
	    py_data = system.dataset.toPyDataSet(dataset)
	    
	  
	    new_data = []
	    
	 
	    for row in py_data:
	        new_row = []
	        for value in row:
	           
	            if isinstance(value, (int, float)) and value in value_mapping:
	                new_row.append(value_mapping[value])
	            else:
	                new_row.append(value)
	        new_data.append(new_row)
	    
	   
	    headers = list(py_data.getColumnNames())
	    

	    return system.dataset.toDataSet(headers, new_data)
	

	transformed_data = transform_dataset(value)
	

	return transformed_data

```

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [May 28, 2024, 2:26pm UTC](https://forum.inductiveautomation.com/t/mapping-transform-in-ignition-perspective/90991/4 "2024-05-28T14:26:45Z")

</div>

You could simplify that a bit if the query returns JSON.

```python
def transform(self, value, quality, timestamp):	
	statusCodes = {
	    1: "Adecuado",
	    2: "Trivial",
	    3: "Tolerable",
	    4: "Moderado",
	    5: "Importante",
	    6: "Intolerable"
	}
	output = []
	for row in value:
		if row['HAZARDVALUE'] in statusCodes:
			status = row['HAZARDVALUE']
		else:
			status = '????'

		output.append({
			"HAZARDVALUE": row['HAZARDVALUE'],
			"status" : status,
			"HAZARD" : row['HAZARD']
		})
	return output

```

---

<div class="post-metadata">

**Author:** ![Alejandro\_Alaco](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/alejandro_alaco/32/59849_2.png) [@Alejandro\_Alaco](https://forum.inductiveautomation.com/u/Alejandro_Alaco)\
**Post date:** [May 28, 2024, 2:39pm UTC](https://forum.inductiveautomation.com/t/mapping-transform-in-ignition-perspective/90991/5 "2024-05-28T14:39:13Z")

</div>

Thanks Transistor!

the code I posted was for another table and named query, for the one in the image I´m using

```python
def transform(self, value, quality, timestamp):
	
	new_headers = [
	    u"Equipos de PCI",
	    u"Instalacion electrica",
	    u"Señalización PCI", 
	    u"Iluminación emergencia", 
	    u"Salidas y vías evac.",  
	    u"Señalización evacuación y",  
	    u"Señalización riesgo elect.",  
	    u"Caída de personas mismo nivel",  
	    u"Escalas fijas",
	    u"Escaleras portátiles de mano", 
	    u"Iluminación PVD",  
	    u"Iluminación resto (no emerg.)",  
	    u"Climatiz. (Temp.)",
	    u"Climatiz. (Hr)",
	    u"Climatiz. (CO2)",
	    u"Caída de objetos desprendidos",  
	    u"Atropellos",
	    u"Tránsito por cubierta",  
	    u"Otros riesgos detallar)"
	]
	

	def transform_dataset(dataset):
	
	    py_data = system.dataset.toPyDataSet(dataset)
	    
	   
	    new_data = []
	    
	 
	    for row in py_data:
	        new_row = list(row)
	        new_data.append(new_row)
	    

	    original_headers = list(py_data.getColumnNames())
	    modified_headers = original_headers[:2] + new_headers[:len(original_headers)-2]
	    
	
	    return system.dataset.toDataSet(modified_headers, new_data)
	
	transformed_data = transform_dataset(value)
	
	
	return transformed_data

```
