Hi Jim,
Thanks for your reply,
I am very sorry, I realize that my request wasn’t very clear.
After prioritizing the group of rows within each Metric (which works well with your script),
I need to select the row of the highest value (Column :metric1), Not based on Max( theRows ) like in the current script.
The dummy table I provided before added to the confusion because "Col Max (:metric1)" within each group is always equal to "Max (theRows)".
Your suggested script doesn't work anymore with a new set of values. Below I replaced :metric1 with :Value to remove the Column name ambiguity, plus I re-shuffled the numerical values.
I tried to play around with "Col Max ()" added as a rule inside the "get rows where()", but wasn’t successful.
(I realize my English is not perfect, so I added an image to describe my goal, if my wording isn't precise enough)
Do you have a suggestion?
Thanks again
Voiz
Names Default To Here( 1 );
dt = New Table( "RawData",
Add Rows( 27 ),
Compress File When Saved( 1 ),
New Column( "Metric",
Character,
"Nominal",
Set Values(
{"A", "A", "A", "A", "A", "A", "A", "B", "B", "B", "B", "B", "B", "C", "C", "C", "C", "C", "C", "C", "D", "D",
"D", "D", "D", "D", "D"}
)
),
New Column( "Flag1",
Character,
"Nominal",
Set Values(
{"FLAG", "OK", "FLAG", "OK", "OK", "OK", "OK", "FLAG", "FLAG", "OK", "OK", "FLAG", "OK", "OK", "FLAG", "FLAG",
"OK", "OK", "OK", "FLAG", "OK", "OK", "OK", "OK", "OK", "OK", "OK"}
)
),
New Column( "Flag2",
Character,
"Nominal",
Set Values(
{"OK", "OK", "OK", "OK", "OK", "FLAG", "OK", "FLAG", "FLAG", "FLAG", "OK", "FLAG", "OK", "OK", "OK", "OK", "OK",
"OK", "OK", "OK", "OK", "OK", "OK", "OK", "OK", "OK", "OK"}
)
),
New Column( "Value",
Numeric,
"Continuous",
Format( "Best", 10 ),
Set Values( [1, 2, 9, 5, 13, 2, 7, 9, 4, 11, 6, 8, 3, 1, 2, 13, 5, 5, 9, 12, 1, 2, 4, 5, 5, 9, 7] )
)
);
dt << clear select;
rowsToSelect = {};
groups = associative array(:metric<<get values) << get keys;
show(groups);
For Each( {group}, groups,
theRows = dt << get rows where( :metric == group & :Flag1 == "FLAG" & :Flag2 == "FLAG"/* & :Value == Col Max (:Value, :Metric, :Flag1, :Flag2)*/);
show (theRows);
If( N Rows( theRows ) > 0,
Insert Into( rowsToSelect, Max( theRows ) ),
theRows = dt << get rows where( :metric == group & (:Flag1 == "FLAG" | :Flag2 == "FLAG") /*& :Value == Col Max (:Value, :Metric, :Flag1, :Flag2)*/ );
show (theRows);
If( N Rows( theRows ) > 0,
Insert Into( rowsToSelect, Max( theRows ) ),
Insert Into( rowsToSelect, Max( dt << get rows where( :metric == group /*& :Value == Col Max (:Value, :Metric, :Flag1, :Flag2)*/) ) );
show (theRows);
);
);
);
dt << select rows( rowsToSelect );