# Comparison between 2 tables

**URL:** <https://forum.inductiveautomation.com/t/comparison-between-2-tables/62056>\
**Category:** Ignition\
**Tags:** ignition81\
**Created:** [July 19, 2022, 12:48pm UTC](https://forum.inductiveautomation.com/t/comparison-between-2-tables/62056 "2022-07-19T12:48:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mjohnson0238](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@mjohnson0238](https://forum.inductiveautomation.com/u/mjohnson0238)\
**Post date:** [July 19, 2022, 12:48pm UTC](https://forum.inductiveautomation.com/t/comparison-between-2-tables/62056/1 "2022-07-19T12:48:44Z")

</div>

How can I make a comparison between 2 tables? I want to check the bottom tables Badge\_Num to the top tables BadgeNum and then change the row color of the top table:

Hers an example:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/0/00dca466da5ced53bf56af678f0a558573dc5d40.png)

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [July 19, 2022, 1:32pm UTC](https://forum.inductiveautomation.com/t/comparison-between-2-tables/62056/2 "2022-07-19T13:32:05Z")

</div>

I’m going to show you how to do it with Python lists. This example assumes each row has some sort of unique value. From your screenshots, I’m going to use “Badge\_Num”. This script is going to be placed in as a change script on `Table_0.props.selection.selectedRow` in my example, but you could modify it to go in other places and just target some index.

I verified this works for two tables using our default data (city/country/population).

```auto
def valueChanged(self, previousValue, currentValue, origin, missedEvents):
	column_with_unique_value = "Badge_Num"
	if currentValue and currentValue.value is not None:
		target_index = None
		# data items can have different structures depending on styling
		try:
			# this covers entries with styling
			city = self.props.data[currentValue.value].get(column_with_unique_value).get("value")
		except AttributeError:
			# this covers standard data
			city = self.props.data[currentValue.value].get(column_with_unique_value)
		other_data = self.getSibling("Table").props.data
		for i in range(len(other_data)):
			# We need the same handling in the other table
			try:
				if other_data[i].get(column_with_unique_value).get("value") == city:
					target_index = i
			except AttributeError:
				if other_data[i].get(column_with_unique_value) == city:
					target_index = i
		self.getSibling("Table").props.selection.selectedRow = target_index

```

---

<div class="post-metadata">

**Author:** ![mjohnson0238](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@mjohnson0238](https://forum.inductiveautomation.com/u/mjohnson0238)\
**Post date:** [July 19, 2022, 2:33pm UTC](https://forum.inductiveautomation.com/t/comparison-between-2-tables/62056/3 "2022-07-19T14:33:44Z")

</div>

> [@cmallonee](#):
>
> ```auto
> for i in range(len(other_data)):
> # We need the same handling in the other table
> try:
> if other_data[i].get(column_with_unique_value).get("value") == city:
> target_index = i
> except AttributeError:
> if other_data[i].get(column_with_unique_value) == city:
> target_index = i
> self.getSibling("Table").props.selection.selectedRow = target_index
> 
> ```

This handling will be in BOTH tables, correct?

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [July 19, 2022, 2:52pm UTC](https://forum.inductiveautomation.com/t/comparison-between-2-tables/62056/4 "2022-07-19T14:52:39Z")

</div>

No, just the table where you are selecting a row manually. In your example above, this script would go into the bottom table.

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [July 19, 2022, 7:35pm UTC](https://forum.inductiveautomation.com/t/comparison-between-2-tables/62056/5 "2022-07-19T19:35:38Z")

</div>

4 posts were split to a new topic: [How to obtain tag value from Qualified Value](https://forum.inductiveautomation.com/t/how-to-obtain-tag-value-from-qualified-value/62089)
