- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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;
));
);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Create "Source Table" Column in Table that references Data Table Name
Thank you!!!
This solves my problem beautifully!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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!