# Perspective table cell number format

**URL:** <https://forum.inductiveautomation.com/t/perspective-table-cell-number-format/102135>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [February 11, 2025, 1:31am UTC](https://forum.inductiveautomation.com/t/perspective-table-cell-number-format/102135 "2025-02-11T01:31:39Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![jrd](https://avatars.discourse-cdn.com/v4/letter/j/b9bd4f/32.png) [@jrd](https://forum.inductiveautomation.com/u/jrd)\
**Post date:** [February 11, 2025, 1:31am UTC](https://forum.inductiveautomation.com/t/perspective-table-cell-number-format/102135/1 "2025-02-11T01:31:39Z")

</div>

Hi  
I am using a perspective table to display some data from a database  
The table has 2 columns, 'loss\_item', and 'loss'  
My transform is:

```python
def transform(self, value, quality, timestamp):
	lst = []
	
	r = [r for r in value if r['resource_id'] == self.view.params.node_name]

	row1 = {'loss_item':'Percent loss', 
			'loss': r[0]['pct_loss_per_run']
			}
	lst.append(row1)
	
	row2 = {'loss_item':'Absolute loss', 
			'loss': r[0]['abs_loss_per_run']
			}
	lst.append(row2)

	row2 = {'loss_item':'Loss cost', 
				'loss': r[0]['loss_cost'],		
			}
	lst.append(row2)
	
	return lst

```

I would like to modify the number format of column 1 ('loss) of each row as follows:  
Row 1 as a percentage (2 decimal places)  
Row 1 as a Float  
Row 3 as a currency

I have searched the forum & user manual, tried various things and came up empty.

Any suggestions?

---

<div class="post-metadata">

**Author:** ![nideyijuyidong](https://avatars.discourse-cdn.com/v4/letter/n/7cd45c/32.png) [@nideyijuyidong](https://forum.inductiveautomation.com/u/nideyijuyidong)\
**Post date:** [February 11, 2025, 2:26am UTC](https://forum.inductiveautomation.com/t/perspective-table-cell-number-format/102135/2 "2025-02-11T02:26:03Z")

</div>

You need to edit `columns` first.

 ![图片](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/b/9bbe938194b860e54323335e773a8d8beb247d26.png)

---

<div class="post-metadata">

**Author:** ![jrd](https://avatars.discourse-cdn.com/v4/letter/j/b9bd4f/32.png) [@jrd](https://forum.inductiveautomation.com/u/jrd)\
**Post date:** [February 11, 2025, 2:40am UTC](https://forum.inductiveautomation.com/t/perspective-table-cell-number-format/102135/3 "2025-02-11T02:40:39Z")

</div>

Thank you  
Pls correct me if I'm wrong, but I think that will make all rows have SAME specified format.  
If possible I need a DIFFERENT format in each row  
Thanks

---

<div class="post-metadata">

**Author:** ![nideyijuyidong](https://avatars.discourse-cdn.com/v4/letter/n/7cd45c/32.png) [@nideyijuyidong](https://forum.inductiveautomation.com/u/nideyijuyidong)\
**Post date:** [February 11, 2025, 2:54am UTC](https://forum.inductiveautomation.com/t/perspective-table-cell-number-format/102135/4 "2025-02-11T02:54:06Z")

</div>

Sorry, I misunderstood.  
If you don't have such high requirements, you can convert all the data into strings.  
If there is a lot of data, you can place multiple tables.  
If you still need to export data, save the original data to a custom params, and then do the above operation, and use the original data when exporting.  
It's really a bit troublesome.

---

<div class="post-metadata">

**Author:** ![David\_Stone](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/david_stone/32/79749_2.png) [@David\_Stone](https://forum.inductiveautomation.com/u/David_Stone)\
**Post date:** [February 11, 2025, 3:24am UTC](https://forum.inductiveautomation.com/t/perspective-table-cell-number-format/102135/5 "2025-02-11T03:24:19Z")

</div>

I think you are using a table for something a table was never meant to be used for.  
You are better off making a dynamic view to show this data, possibly one with a flex repeater and use parameters to distinguish the rows for data handling.

---

<div class="post-metadata">

**Author:** ![jrd](https://avatars.discourse-cdn.com/v4/letter/j/b9bd4f/32.png) [@jrd](https://forum.inductiveautomation.com/u/jrd)\
**Post date:** [February 11, 2025, 4:02am UTC](https://forum.inductiveautomation.com/t/perspective-table-cell-number-format/102135/6 "2025-02-11T04:02:06Z")

</div>

You are correct of course David !  
I wanted to use a table to maintain the aesthetics of my page and was hoping there may be a smart way!

---

<div class="post-metadata">

**Author:** ![hunterdg](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/hunterdg/32/67774_2.png) [@hunterdg](https://forum.inductiveautomation.com/u/hunterdg)\
**Post date:** [February 11, 2025, 6:11am UTC](https://forum.inductiveautomation.com/t/perspective-table-cell-number-format/102135/7 "2025-02-11T06:11:33Z")

</div>

this may be useful: [Embedding a View in a Table Cell](https://www.docs.inductiveautomation.com/docs/8.1/appendix/components/perspective-components/perspective-display-palette/perspective-table/table-column-configurations#embedding-a-view-in-a-table-cell), perhaps with additional (hidden) columns that define the formatting per-cell. Could even make it just one additional column with json-encoded formatting/viewPath params for every cell in the row.

---

<div class="post-metadata">

**Author:** ![David\_Stone](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/david_stone/32/79749_2.png) [@David\_Stone](https://forum.inductiveautomation.com/u/David_Stone)\
**Post date:** [February 11, 2025, 7:36am UTC](https://forum.inductiveautomation.com/t/perspective-table-cell-number-format/102135/8 "2025-02-11T07:36:07Z")

</div>

There is no reason your dynamic view can't look exactly like a table, the table itself is built from just styled containers at a root level. Follow the spacing and the css colours etc from a table in developer view in a browser then recreate it in the view.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [February 11, 2025, 8:47am UTC](https://forum.inductiveautomation.com/t/perspective-table-cell-number-format/102135/9 "2025-02-11T08:47:55Z")

</div>

May I suggest a slight rewrite of the transform:

```python
def transform(self, value, quality, timestamp):
	row = next(r for r in value if r['resource_id'] == self.view.params.node_name)
	return [
		{
			'loss_item': "Percent loss",
			'loss': row['pct_loss_per_run']
		},
		{
			'loss_item': "Absolute loss",
			'loss': row['abs_loss_per_run']
		},
		{
			'loss_item': "Loss cost",
			'loss': row['loss_cost']
		}
	]

```

If you're looking for one specific row, use `next`. As you can see, it can also take a generator expression (the same thing you use in comprehensions). This has 2 benefits:

- You get the row directly, instead of a list with. No need get its first item.
- It stops as soon as it find the row, instead of processing the whole list

If it's possible the row doesn't exist, you can either catch the 'StopIteration' it raises:

```python
try:
	next(...)
except StopIteration:
	logger.info("row not found")

```

Or give a default to `next`:

```python
next((v for v in value if r == x), default)

```

You can easily change the format of whatever value you put in your table if you convert it to string in the transform, if you really want to keep using a table:

```python
return [
	{
		'loss_item': "Percent loss",
		'loss': "{:.2f}%".format(row['pct_loss_per_run'])
	}
	...
]

```

Note that using floats for currency might result in less than ideal outputs. It's usually a good idea to use integers, one for the integer part, and another one for the decimal part.  
That's because float operations are not guaranteed to be exact, ie:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/9/b9cd35fc9a9c3a4b0b0428655bc4b58b68c3d0a3.png)

---

<div class="post-metadata">

**Author:** ![jrd](https://avatars.discourse-cdn.com/v4/letter/j/b9bd4f/32.png) [@jrd](https://forum.inductiveautomation.com/u/jrd)\
**Post date:** [February 11, 2025, 11:09pm UTC](https://forum.inductiveautomation.com/t/perspective-table-cell-number-format/102135/10 "2025-02-11T23:09:29Z")

</div>

Thank you all for the inputs  
I will review and advise result shortly
