WHAT I'M DOING:
1. Loading two large data tables (one with 100k+ rows)
2. Joining them by matching keys
3. Extracting unique values from all filter columns and storing them in a separate cache table
4. Creating a custom UI with multiple ComboBox dropdowns (13 filters total)
5. Loading ComboBox values from the cache table
6. User selects values from dropdowns and clicks button to create a filtered subset
// This is simplified version:
Clear Log();
// Step 1-2: Load and join two tables
LoadAndJoinData = Function({},
dt_results = Data Table("Table1");
dt_tracker = Data Table("Table2");
// Join tables by matching key
dt_joined = dt_results << Join(
With(dt_tracker),
By Matching Columns(:key1 = :key2),
Drop multiples(0, 0),
Output Table("Joined_Data")
);
Return(dt_joined);
);
// Step 3: Create cache table with unique values - THIS IS SLOW
CreateFilterCache = Function({dt_source},
Print("Creating filter cache table...");
// Create cache table to store unique values
dt_cache = New Table("Filter_Cache",
New Column("Filter_Name", Character),
New Column("Filter_Value", Character)
);
column_list = {"Column1", "Column2", "Column3", "Column4", "Column5"};
current_row = 0;
For(i = 1, i <= N Items(column_list), i++,
col_name = column_list[i];
Print(" Processing: " || col_name);
// Extract unique values
col = Column(dt_source, col_name);
col_values = col << Get Values;
aa = Associative Array();
For(j = 1, j <= N Items(col_values), j++,
val = col_values[j];
If(!Is Missing(val) & val != "",
aa[val] = 1;
);
);
unique_list = aa << Get Keys;
unique_list = Sort Ascending(unique_list);
// Store in cache table
For(k = 1, k <= N Items(unique_list), k++,
current_row++;
dt_cache << Add Rows(1);
dt_cache:Filter_Name[current_row] = col_name;
dt_cache:Filter_Value[current_row] = unique_list[k];
);
);
Print("Cache table created with " || Char(N Rows(dt_cache)) || " entries");
Return(dt_cache);
);
// Step 5: Load unique values from cache table
GetValuesFromCache = Function({dt_cache, column_name},
value_list = {};
For(i = 1, i <= N Rows(dt_cache), i++,
If(dt_cache:Filter_Name[i] == column_name,
Insert Into(value_list, dt_cache:Filter_Value[i]);
);
);
Insert Into(value_list, "", 1);
Return(value_list);
);
// Step 4-5: Create filter window and load from cache
CreateFilterWindow = Function({dt_final, dt_cache},
Print("Loading dropdowns from cache...");
// Load from cache - STILL SLOW for large lists
unique_col1 = GetValuesFromCache(dt_cache, "Column1");
unique_col2 = GetValuesFromCache(dt_cache, "Column2");
unique_col3 = GetValuesFromCache(dt_cache, "Column3");
unique_col4 = GetValuesFromCache(dt_cache, "Column4");
unique_col5 = GetValuesFromCache(dt_cache, "Column5");
Print("Creating window...");
win = New Window("Custom Filter",
V List Box(
Panel Box("Select Filters",
V List Box(
H List Box(
Text Box("Filter 1:"),
cb_1 = Combo Box(unique_col1, "", <<Set Width(150))
),
H List Box(
Text Box("Filter 2:"),
cb_2 = Combo Box(unique_col2, "", <<Set Width(150))
),
H List Box(
Text Box("Filter 3:"),
cb_3 = Combo Box(unique_col3, "", <<Set Width(200))
),
H List Box(
Text Box("Filter 4:"),
cb_4 = Combo Box(unique_col4, "", <<Set Width(200))
),
H List Box(
Text Box("Filter 5:"),
cb_5 = Combo Box(unique_col5, "", <<Set Width(200))
)
)
),
Button Box("Create Subset",
sel_1 = cb_1 << Get Selected;
sel_2 = cb_2 << Get Selected;
sel_3 = cb_3 << Get Selected;
sel_4 = cb_4 << Get Selected;
sel_5 = cb_5 << Get Selected;
// Step 6: Filter data - also slow with manual loop
dt = Data Table("Joined_Data");
rowList = {};
For(i = 1, i <= N Rows(dt), i++,
include = 1;
If(sel_1 != "" & dt:Column1[i] != sel_1, include = 0);
If(sel_2 != "" & dt:Column2[i] != sel_2, include = 0);
If(sel_3 != "" & dt:Column3[i] != sel_3, include = 0);
If(sel_4 != "" & dt:Column4[i] != sel_4, include = 0);
If(sel_5 != "" & dt:Column5[i] != sel_5, include = 0);
If(include, Insert Into(rowList, i));
);
If(N Items(rowList) > 0,
dt_subset = dt << Subset(
Output Table Name("Filtered_" || Format(Today(), "yyyy-mm-dd")),
Rows(rowList)
);
Print("Subset created: " || Char(N Rows(dt_subset)) || " rows");
);
)
)
);
);
// Main execution
dt_joined = LoadAndJoinData();
dt_cache = CreateFilterCache(dt_joined); // Create cache once
CreateFilterWindow(dt_joined, dt_cache); // Use cached values