This is definitely not the only way of doing this, but one possible option
Names Default To Here(1);
dt = New Table("Untitled",
Add Rows(10),
Compress File When Saved(1),
New Column("Month",
Character,
"Nominal",
Set Values({"Jan", "Jan", "Jan", "Feb", "Feb", "Feb", "Mar", "Mar", "Apr", "Apr"})
),
New Column("Serial # of unit tested",
Numeric,
"Nominal",
Format("Best", 12),
Set Values([1001, 1001, 1002, 1002, 1003, 1004, 1005, 1006, 1006, 1006])
)
);
dt_results = New Table("Untitled 3",
Compress File When Saved(1),
New Column("Month", Character, "Nominal", Set Values({})),
New Column("# of tests, prior 3 months", Numeric, "Continuous", Format("Best", 12), Set Values([])),
New Column("# of unique SN tested, prior 3 months", Numeric, "Continuous", Format("Best", 12), Set Values([]))
);
//
order = {"Jan", "Feb", "Mar", "Apr"};
Summarize(dt, uniq_months = By(:Month));
For Each({cur_month}, uniq_months,
cur_month_idx = Contains(order, cur_month);
months_of_interest = If(cur_month_idx < 3,
order[1::cur_month_idx];
,
order[(cur_month_idx - 2)::cur_month_idx];
);
// number of tests is same as number of rows
rows_of_interest = dt << Get Rows Where(Contains(months_of_interest, :Month));
nr_of_tests = N Items(rows_of_interest);
// number of unique items we can get with associative array
unique_snrs = Associative Array(dt[rows_of_interest, "Serial # of unit tested"]) << get keys;
nr_of_unique = N Items(unique_snrs);
cur_month_result = Eval List({cur_month, nr_of_tests, nr_of_unique});
dt_results << Add Row(1);
dt_results[N Row(dt_results), 0] = cur_month_result;
);
If you have multiple years it will require modifications
-Jarmo