我一直在嘗試最簡單的方法來對具有組或類別的資料的以下資料進行密集排名。我問過類似的問題來對資料進行排名,但這個問題是針對分組資料的。
我希望按如下所示對分數列進行排名,以使最高數字排在第 1 位=第 1 位。第二大的數字排在第二位,依此類推。如果有平局,則給他們相同的排名順序。比如說 ID=3002 的 score=200,ID=3010 出現兩次,在 SS3 類中排名第一。所以在這種情況下,得分手將具有相同的排名 => 密集排名。所有的課程都是一樣的。
類代表編隊組。每個人,將按每個班級進行評分。所有方法都有google,看起來很麻煩,并且不知何故占用了更多的powerquery記憶體空間。但是,多虧了這個平臺上的某個人,這提供了一種快速解決問題的好方法。他提供了以下自定義函式來處理此趨勢中所討論的這種情況:如何使用 Powerquery 在表中有效地密集排列組我發現在他的函式中,一些列值是硬編碼的。所以如果我有幾個列值,我會需要手動添加。如何有效處理這個問題?
分數 | ID | 班級 | 阿拉伯 | 數學 | 秩 |
---|---|---|---|---|---|
130 | 1002 | SS1 | 30 | 100 | |
180 | 2003年 | SS2 | 100 | 80 | |
140 | 1006 | SS1 | 90 | 50 | |
130 | 1007 | SS1 | 80 | 50 | |
200 | 3002 | SS3 | 100 | 100 | |
200 | 3010 | SS3 | 100 | 100 | |
70 | 3010 | SS3 | 50 | 20 |
預期成績
分數 | ID | 班級 | 阿拉伯 | 數學 | 秩 |
---|---|---|---|---|---|
130 | 1002 | SS1 | 30 | 100 | 第二 |
180 | 2003年 | SS2 | 100 | 80 | 第一 |
140 | 1006 | SS1 | 90 | 50 | 第一 |
130 | 1007 | SS1 | 80 | 50 | 第二 |
200 | 3002 | SS3 | 100 | 100 | 第一 |
200 | 3010 | SS3 | 100 | 100 | 第一 |
70 | 3010 | SS3 | 50 | 20 | 第三 |
uj5u.com熱心網友回復:
在對班級分組后對分數列進行排名怎么樣,適用于任意數量的列
let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Added Index" = Table.AddIndexColumn(Source, "Index", 0, 1, Int64.Type), //optional
#"Grouped Rows" = Table.Group(#"Added Index", {"Class"}, {{"data", each rank(_,"Scores","Rank"), type table }}),
ColumnsToExpand = List.Difference(List.Distinct(List.Combine(List.Transform(Table.Column(#"Grouped Rows", "data"), each if _ is table then Table.ColumnNames(_) else {}))),{"Class"}),
DynamicExpanded = Table.ExpandTableColumn(#"Grouped Rows", "data",ColumnsToExpand ,ColumnsToExpand ),
#"Sorted Rows" = Table.Sort(DynamicExpanded,{{"Index", Order.Ascending}}), // optional
#"Removed Columns" = Table.RemoveColumns(#"Sorted Rows",{"Index"}) // optional
in #"Removed Columns"
使用這個函式,命名為rank
(Source as table, RankColumnName as text, optional OutputName as nullable text) =>
let #"Added Index" = Table.AddIndexColumn(Source, "RankIndex", 0, 1, Int64.Type),
#"Grouped Rows" = Table.Group(#"Added Index", RankColumnName, {{"data", each _, type table}}),
#"Sorted Rows" = Table.Sort(#"Grouped Rows",{{RankColumnName, Order.Descending}}),
#"Added Index1" = Table.AddIndexColumn(#"Sorted Rows", if OutputName=null or OutputName="" then"Rank" else OutputName, 1, 1, Int64.Type),
#"Removed Columns" = Table.RemoveColumns(#"Added Index1",RankColumnName),
#"Expanded data" = Table.ExpandTableColumn(#"Removed Columns", "data", Table.ColumnNames(#"Added Index"), Table.ColumnNames(#"Added Index")),
#"Sorted Rows2" = Table.Buffer(Table.Sort(#"Expanded data",{{"RankIndex", Order.Ascending}})), // optional
#"Removed Columns1" = Table.RemoveColumns(#"Sorted Rows2",{"RankIndex"})
in #"Removed Columns1"
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/508010.html
上一篇:獲取列中第一個不為0的值