Thanks @txnelson! I like this approach, but not all of my assemblies can be built with the same Part Numbers and it would be difficult to look at thousands of assemblies and parts. I probably simplified my example too much and added a very complex explanation on top of it.
I made some progress on an approach that I think will work. I was able to figure out how to dynamically create associative arrays for every Assembly-Location and the Part Numbers that go with it. Here is the script:
dt=Data Table( "Example" );
//Combine columns to get a single unique identifer for each row
dt << Combine Columns(
delimiter( "_" ),
Columns( :Assembly, :Location ),
Selected Columns are Indicator Columns( 0 ),
Column Name( "Assembly_Location" )
);
//Creates columns for each Assembly_Location - Grouping Like Part numbers together
dt1=dt << Split(
Split By( :Assembly_Location ),
Split( :Part Number ),
Remaining Columns( Drop All ),
Sort by Column Property,
Table Name ("Transposed Example")
);
//Get all column names as a list
allnames=dt1<<get column names(string);
//Create an associative array for every column with the column name used as the array name
for (i = 1, i <= nitems(allnames), i++,
// If it's a string column then create the column name and an array name for use as a dynamic input
if (is string(allnames[i]),
col_name = "dt1:Name(\!"" || allnames[i]||"\!")" ;
array_name = "aa" || allnames[i];
// Build associative array string dynamically and then execute it.
str = evalinsert(
"\[^array_name^=Associative Array (^col_name^) ;]\");
eval(parse(str));
);
);
aaKBR175_001;
aaKBR175_002;
aaKBR175_003;
Now I want to compare each array to the others and see if there is any overlap. If there is, I want to combine the arrays. For Example, looking at KBR175-001 (20-0002, 20-0003, 20-0004, 20-0005), TRT330-003 (20-0002, 20-0003, 20-0004), NTE484-001 (20-0002, 20-0003, 20-0005, 20-0007), KNW995-002 (20-0002, 20-0003, 20-0004, 20-0005). The result would be: (20-0002, 20-0003, 20-0004, 20-0005, 20-0007).
I thought I could use the intersect operation, but that replaces the first array with the results of the intersection:
//Creates an Associative Array for each two columns
aa1=Associative Array (dt1:Name("KBR175_001") );
aa3=Associative Array (dt1:Name("NTE484_001") );
//Looks for overlap
aa1 << intersect ( aa3 );
Show(N Items(aa1));
//If there is overlap, it combines the two Arrays into one, otherwise it returns "no"
if (N Items (aa1)>0, aa1<< Insert( aa3 ), Show("no"));
But this only gives me the intersection of aa1 and aa3 plus aa3 or {"20-0002", "20-0003", "20-0005", "20-0007"} I have excluded "20-0004" which was originally part of aa1.
My question is two part:
1. Is there a way to compare arrays and then combine both arrays to include all keys?
2. How would I compare all arrays to all other arrays? I assume some sort of For Loop.