Another way to do the same thing. Not better, just different:
Names Default To Here(1);
dt1 = New Table("Untitled1",
Add Rows(3),
Compress File When Saved(1),
New Column("data", Character, "Nominal", Set Values({"a", "b", "c"})),
New Column("date", Numeric, "Continuous", Format("Best", 12), Set Values([2021, 2021, 2021])),
New Column("a", Numeric, "Continuous", Format("Best", 12), Set Values([0, 50, 2])),
New Column("c", Numeric, "Continuous", Format("Best", 12), Set Values([1, 0, 0])),
New Column("f", Numeric, "Continuous", Format("Best", 12), Set Values([0, 0, 7]))
);
dt2 = New Table("Untitled2",
Add Rows(3),
Compress File When Saved(1),
New Column("data", Character, "Nominal", Set Values({"a", "b", "c"})),
New Column("date", Numeric, "Continuous", Format("Best", 12), Set Values([2021, 2021, 2021])),
New Column("a", Numeric, "Continuous", Format("Best", 12), Set Values([0, 50, 2])),
New Column("b", Numeric, "Continuous", Format("Best", 12), Set Values([1, 0, 0])),
New Column("r", Numeric, "Continuous", Format("Best", 12), Set Values([0, 0, 7])),
New Column("x", Numeric, "Continuous", Format("Best", 12), Set Values([2, 7, 1]))
);
//Put all in one table
dtConcat = dt1 << Concatenate(
dt2,
Create source column
);
//Unpivot - one column with all values
dtStacked = dtConcat << Stack(
columns( 4::n col(dtConcat) ),
Source Label Column( "Column" ),
Stacked Data Column( "Value" )
);
//Use tabulate to find sums
dtSum = (tab = dtStacked << Tabulate(
Add Table(
Column Table( Grouping Columns( :Column ), Analysis Columns( :Value ) )
)
)) << Make Into Data Table;
//Clean Up
tab << Close Window;
dtStacked << Close Window; dtConcat << Close Window;
dt1 << Close Window; dt2 << Close Window;