cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
kmprosperi
Level I

Create "Source Table" Column in Table that references Data Table Name

Hi!

I'd like to create a column called "Source Table" that auto populates with the name of data table that is being worked on.
This is done when concatenating multiple file names; but I'd like to do it at the start of all my workflows as a matter of practice (without having to manually add it).

Is this possible?
Thanks!
Katie

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: Create "Source Table" Column in Table that references Data Table Name

You could at least add a small script to perform that column creation. Here is one option for that

 

Local({dt, newcol},
	dt = Current Data Table();
	If(!Contains(dt << Get Column Names("String"), "Source"),
		newcol = dt << New Column("Source", Character, Nominal, Formula(
			dt << get name;
		));
		dt << Run Formulas;
		newcol << Delete Formula;
	);
);

(I added If statement to avoid re-creation of the column if Source column already exists, but you can drop it if it isn't needed)

 

 

-Jarmo

View solution in original post

5 REPLIES 5
jthi
Super User

Re: Create "Source Table" Column in Table that references Data Table Name

You could at least add a small script to perform that column creation. Here is one option for that

 

Local({dt, newcol},
	dt = Current Data Table();
	If(!Contains(dt << Get Column Names("String"), "Source"),
		newcol = dt << New Column("Source", Character, Nominal, Formula(
			dt << get name;
		));
		dt << Run Formulas;
		newcol << Delete Formula;
	);
);

(I added If statement to avoid re-creation of the column if Source column already exists, but you can drop it if it isn't needed)

 

 

-Jarmo
jthi
Super User

Re: Create "Source Table" Column in Table that references Data Table Name

Also in this case you can use Set Each Value, it makes the script a bit simpler

Local({dt, newcol},
	dt = Current Data Table();
	If(!Contains(dt << Get Column Names("String"), "Source"),
		newcol = dt << New Column("Source", Character, Nominal, Set Each Value(
			dt << get name;
		));
	);
);

Edit:

A bit cleaned version below, as this doesn't need Local() (I added it for newcol variable to make it easier to remove the formula from created column for the formula version)

 

If(!Contains(Current Data Table() << Get Column Names("String"), "Source"),
	Current Data Table() << New Column("Source", Character, Nominal, Set Each Value(
		Current Data Table() << get name;
	));
);

 

-Jarmo
kmprosperi
Level I

Re: Create "Source Table" Column in Table that references Data Table Name

Thank you!!! 
This solves my problem beautifully!

txnelson
Super User

Re: Create "Source Table" Column in Table that references Data Table Name

Here is a Work Flow step that can be added that adds the Source Table column to the current data table

txnelson_0-1719862133916.png

txnelson_1-1719862163675.png

 

Jim
kmprosperi
Level I

Re: Create "Source Table" Column in Table that references Data Table Name

Thank you!! I am stepping away from standalone scripts & into the world of workflows!  This will be helpful!