Input collection: myHighScores28
Name | Value |
Jim Anderson | 100 |
Winnie Lee | 78 |
Jane Nelson | 100 |
Anders Erickson | 135 |
Timothy Green | 15 |
Elizabeth Martin | 50 |
Output collection: mySolution28
Name | Value |
Anders Erickson | 135 |
Jim Anderson | 100 |
Jane Nelson | 100 |
Winnie Lee | 75 |
Elizabeth Martin | 50 |
Timothy Green | 15 |
Solution code:
//Create a collection
ClearCollect(myHighScores28,
{Name: "Jim Anderson", Value: 100},
{Name: "Winnie Lee", Value: 75},
{Name: "Jane Nelson", Value: 100},
{Name: "Anders Erickson", Value: 135},
{Name: "Timothy Green", Value: 15},
{Name: "Elizabeth Martin", Value: 50}
);
//Rank from highest to lowest code
ClearCollect(
myCountedValues,
Sort(
AddColumns(
GroupBy(myHighScores28,"Value","GroupedValues"),
"CountValue",CountRows(GroupedValues)
),
Value,Descending
)
);
//Rank counter collection
ClearCollect(rowCounter,{Value:1});
//Rank from highest to lowest code continued
Clear(myRankedValues);
ForAll(
myCountedValues,
Collect(
myRankedValues,
{
RankNumber: First(rowCounter).Value,
Value: myCountedValues[@Value],
CountValue: myCountedValues[@CountValue],
GroupedValues: myCountedValues[@GroupedValues]
});
Patch(
rowCounter,
First(rowCounter),
{Value: First(Sort(myRankedValues,RankNumber,Descending)).RankNumber + CountValue}
);
);
ClearCollect(
mySolution28,
Sort(
DropColumns(Ungroup(myRankedValues,"GroupedValues"),"CountValue"),
RankNumber,
Ascending
)
);