Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

- JMP User Community
- :
- Discussions
- :
- Is there a way to iterate an If statement on the last row of a table?

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

May 4, 2020 8:39 AM
(939 views)

we have a table that is created from a db query. We use the date/time stamps in this table to determine start/stop times for more detailed queries. The problem we are having is that sometimes the date/time stamps at the end of the table are not a 'matched' set. In this table, we have created formula columns that help us identify which dates are on which row. We know the pattern that we need to have: the last two rows in X_3 need to end in 1 then 0.

```
If(dt:X_3[NRow(dt)-1] == 0, dt<< deleteRows(NRow(dt)));
If(dt:X_3[NRow(dt)] == 1, dt<< deleteRows(NRow(dt)));
```

Is there a way to iterate only on the last row until the table has the desired structure?

David Zetune

1 ACCEPTED SOLUTION

Accepted Solutions

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

In the end, what I needed looked like this

```
While( continue,
If( dt:X_3[N Row( dt ) - 1] == 0,
dt << deleteRows( N Row( dt ) ),
continue = 0
)
);
```

Thanks

David Zetune

4 REPLIES 4

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Is there a way to iterate an If statement on the last row of a table?

Created:
May 4, 2020 11:18 AM
| Last Modified: May 4, 2020 11:19 AM
(922 views)
| Posted in reply to message from zetunedav 05-04-2020

I would be careful deleting rows from within a formula column. Every time the formula is re-evaluated, it will chop off the last row. However you can create a logical condition for the last row in a column formula using something like this:

`If( Row() == N Row(Current Data Table()), do this, do that);`

For your situation, I would run a separate script, not as in a formula column, to cut off the last row so you don't leave that code as a permanent feature of your resulting data table. In that case, the script would pretty much look like what you have.

-- Cameron Willden

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Is there a way to iterate an If statement on the last row of a table?

@cwillden Thanks for the input. I'm more interested in the second option. However, the number of rows that need to be trimmed off the bottom varies. I was hoping I could evaluate the last row, delete it and re-valuate the If statement on the 'new' last row in a loop until the Else becomes true.

David Zetune

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Is there a way to iterate an If statement on the last row of a table?

Just to close the loop on this post for now, @zetunedav realized we actually work for the same company (and know each other

-- Cameron Willden

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

In the end, what I needed looked like this

```
While( continue,
If( dt:X_3[N Row( dt ) - 1] == 0,
dt << deleteRows( N Row( dt ) ),
continue = 0
)
);
```

Thanks

David Zetune

Article Labels

There are no labels assigned to this post.