turn on suggestions

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

Showing results for

- JMP User Community
- :
- Discussions
- :
- Newbie help with Dialog variable to use within a f...

Topic Options

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

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

Feb 23, 2017 11:32 AM
(1274 views)

Hi I'm trying a basic Delta between 2 columns which I want to choice using a dialog to choose both columns and use a basic delta X-Y formulae. However, I don't seem to be able to work out the correct syntax for this. The formulae is not carrying into the new column which is being created. When I hover over the my_X and my_Y field they do bring up the correct names. Can you advice...

dt_values = Current Data Table**()**;

cdlg = Column Dialog**(** yCols = ColList**(** "POR", MinCol**(** **1** **)**, MaxCol**(** **1** **)** **)** **)**;

my_Y = cdlg**[**"yCols"**]**;

cdlg = Column Dialog**(** xCols = ColList**(** "Diff", MinCol**(** **1** **)**, MaxCol**(** **1** **)** **)** **)**;

my_X = cdlg**[**"xCols"**]**;

dt_values << **new column(**"Delta", Numeric, Format**(** "Fixed Dec", **10**, **2** **)**, formula**(** Column**(**my_X**[****1])** **)** - **(**Column**(**my_Y**[****1])))**;

Basic Table

A | B | Delta |

1 | 3 | |

2 | 12 |

1 ACCEPTED SOLUTION

Accepted Solutions

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

Feb 23, 2017 2:37 PM
(2485 views)

Solution

Here is a solution to your script.

```
dt_values = Current Data Table();
cdlg = Column Dialog( yCols = ColList( "POR", MinCol( 1 ), MaxCol( 1 ) ) );
my_Y = cdlg["yCols"];
cdlg = Column Dialog( xCols = ColList( "Diff", MinCol( 1 ), MaxCol( 1 ) ) );
my_X = cdlg["xCols"];
dt_values << New Column( "Delta",
Numeric,
Format( "Fixed Dec", 10, 2 ),
formula( eval(my_X[1] ) - eval( my_Y[1] ))
);
```

However, a better version of your code is:

```
dt_values = Current Data Table();
cdlg = Column Dialog( yCols = ColList( "POR", MinCol( 1 ), MaxCol( 1 ) ) ,xCols = ColList( "Diff", MinCol( 1 ), MaxCol( 1 ) ) );
my_Y = cdlg["yCols"];
my_X = cdlg["xCols"];
Eval(
Substitute(
Expr(
dt_values << New Column( "Delta", Numeric, Format( "Fixed Dec", 10, 2 ), formula( _x_ - _y_ ) )
),
Expr( _x_ ), Parse( ":" || Char( my_X[1] ) ),
Expr( _y_ ), Parse( ";" || Char( my_Y[1] ) )
));
```

A final comment: JMP has downgraded the value of the Column Dialog function, and points users to use a "Modal" New Window() function. You can see illustrations on how to do this in:

Help==>Books==>Scripting Guide

Jim

4 REPLIES

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

Feb 23, 2017 12:14 PM
(1262 views)

Hi Bill,

You can generate a new difference column by highlighting the two columns of interest and then right click in the column header. Go to the New Formula Column tab and click to follow the prompts. An example is shown below.

HTH

Bill W.

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

Feb 23, 2017 12:27 PM
(1259 views)

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

Feb 23, 2017 2:37 PM
(2486 views)

Here is a solution to your script.

```
dt_values = Current Data Table();
cdlg = Column Dialog( yCols = ColList( "POR", MinCol( 1 ), MaxCol( 1 ) ) );
my_Y = cdlg["yCols"];
cdlg = Column Dialog( xCols = ColList( "Diff", MinCol( 1 ), MaxCol( 1 ) ) );
my_X = cdlg["xCols"];
dt_values << New Column( "Delta",
Numeric,
Format( "Fixed Dec", 10, 2 ),
formula( eval(my_X[1] ) - eval( my_Y[1] ))
);
```

However, a better version of your code is:

```
dt_values = Current Data Table();
cdlg = Column Dialog( yCols = ColList( "POR", MinCol( 1 ), MaxCol( 1 ) ) ,xCols = ColList( "Diff", MinCol( 1 ), MaxCol( 1 ) ) );
my_Y = cdlg["yCols"];
my_X = cdlg["xCols"];
Eval(
Substitute(
Expr(
dt_values << New Column( "Delta", Numeric, Format( "Fixed Dec", 10, 2 ), formula( _x_ - _y_ ) )
),
Expr( _x_ ), Parse( ":" || Char( my_X[1] ) ),
Expr( _y_ ), Parse( ";" || Char( my_Y[1] ) )
));
```

A final comment: JMP has downgraded the value of the Column Dialog function, and points users to use a "Modal" New Window() function. You can see illustrations on how to do this in:

Help==>Books==>Scripting Guide

Jim

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

Feb 24, 2017 5:29 AM
(1235 views)

Thanks for both codes, they both worked. I've used the 2nd :-)

I'll review the modal as per your recommendation, but curious as to whether the dialog will still work in future as many scripts currently use the dialog functionality at moment.