# Delete Column from a Table

**URL:** <https://forum.inductiveautomation.com/t/delete-column-from-a-table/29404>\
**Category:** Ignition\
**Created:** [October 25, 2019, 5:58pm UTC](https://forum.inductiveautomation.com/t/delete-column-from-a-table/29404 "2019-10-25T17:58:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![bbranison](https://avatars.discourse-cdn.com/v4/letter/b/74df32/32.png) [@bbranison](https://forum.inductiveautomation.com/u/bbranison)\
**Post date:** [October 25, 2019, 5:58pm UTC](https://forum.inductiveautomation.com/t/delete-column-from-a-table/29404/1 "2019-10-25T17:58:14Z")

</div>

I need a way to remove a column from a dataset by column index or name. I’ve been toying with a loop through the dataset based on a list of the headers for the columns I want to keep, but coming up short. Any help would be greatly appreciated.  
Thanks!

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [October 25, 2019, 6:01pm UTC](https://forum.inductiveautomation.com/t/delete-column-from-a-table/29404/2 "2019-10-25T18:01:19Z")

</div>

There an [expression function](https://docs.inductiveautomation.com/display/DOC80/columnRearrange) and a [scripting function](https://docs.inductiveautomation.com/display/DOC80/system.dataset.filterColumns) that do this for you.

---

<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:** [October 25, 2019, 6:17pm UTC](https://forum.inductiveautomation.com/t/delete-column-from-a-table/29404/3 "2019-10-25T18:17:00Z")

</div>

@pturmel: Not fair - I got called into a meeting.

---

<div class="post-metadata">

**Author:** ![bbranison](https://avatars.discourse-cdn.com/v4/letter/b/74df32/32.png) [@bbranison](https://forum.inductiveautomation.com/u/bbranison)\
**Post date:** [October 25, 2019, 6:38pm UTC](https://forum.inductiveautomation.com/t/delete-column-from-a-table/29404/4 "2019-10-25T18:38:21Z")

</div>

Can’t believe I missed that scripting function. Thanks for your help!

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [October 25, 2019, 6:53pm UTC](https://forum.inductiveautomation.com/t/delete-column-from-a-table/29404/5 "2019-10-25T18:53:12Z")

</div>

> [@cmallonee](#):
>
> Not fair

Heh. I'm having a rare quiet afternoon--more time for the forum. (:

{ The calm before next week's scheduled storm. }

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [April 3, 2023, 11:51pm UTC](https://forum.inductiveautomation.com/t/delete-column-from-a-table/29404/6 "2023-04-03T23:51:52Z")

</div>

I just had this issue too, and `filterColumn` certainly isn't the obvious solution. Filtering a dataset is a different action to explicitly removing columns. It would still be good to have a "removeColumns" function to remove certain columns instead of having to do the invert of this.

I wrote a function to do it for me:

```auto
def removeColumns(ds, colsRemove):
	""" Removes columns from a dataset. colsRemove should be a list of column names to remove. """
	colsKeep = ds.columnNames
	for col in colsRemove: colsKeep.remove(col)
	
	ds = system.dataset.filterColumns(ds, colsKeep)
	return ds

```

On another note, @Paul.Scott it would be good it the doco pointed out that this function (filterColumns) can also be used to inadvertently re-arrange columns in a dataset as well, as columns will appear in the order in which you define in the filter columns list.
