排名数据的两个维度

我有两个维度的数据集,像这样:

ABC A - 9 4 B 24 - 13 C 3 12 - 

它代表了两个实体之间的关系。 我想返回这些值的列表,如:

 AB:4
 AC:5
 BA:1
 BC:2
 CA:6
 CB:3 

任何想法最好的方法来处理这个?

创build你的源matrix的副本,假设布局如下,

 =IFERROR(RANK(B2,$B$2:$D$4),"") 

在G2中复制到I4。 从这个排名的2D版本创build一个数据透视表与多个合并范围(“反向枢轴” – 也许Alt + D,P)。 双击Total s intersect。 如果结果复制回源表如下(为了方便起见),在U2中join=Q2&R2&": "&S2 (或相应地调整)并复制以适应:

SO18387948的例子

可能更适合更大的数据集!

您也可以使用VBA从汇总表创build一个统一的表格。 从那以后,使用CONCATENATERANK就可以很容易地根据它们的数值进行sorting。

我们假设这是你的起始表:

在这里输入图像说明

这是将这个数据透视表转换为一个平坦的表的VBA代码:( 转到开发工具栏 – > Visual Basic – > 插入 – > 模块 – >复制粘贴代码在这里)

然后点击运行 (绿色播放标志)

  Sub ReversePivotTable() ' Before running this, make sure you have a summary table with column headers. ' The output table will have three columns. Dim SummaryTable As Range, OutputRange As Range Dim OutRow As Long Dim r As Long, c As Long On Error Resume Next Set SummaryTable = ActiveCell.CurrentRegion With SummaryTable r = Application.Match("Totals", Columns(1), False) c = Application.Match("Total", Rows(1), False) End With Set SummaryTable = SummaryTable.Resize(r - 1, c - 1) MsgBox SummaryTable.Address If SummaryTable.Count = 1 Or SummaryTable.Rows.Count < 3 Then MsgBox "Select a cell within the summary table.", vbCritical Exit Sub End If SummaryTable.Select Set OutputRange = Application.InputBox(prompt:="Select a cell for the 3-column output", Type:=8) ' Convert the range OutRow = 2 Application.ScreenUpdating = False OutputRange.Range("A1:C3") = Array("Column1", "Column2", "Column3") For r = 2 To SummaryTable.Rows.Count For c = 2 To SummaryTable.Columns.Count OutputRange.Cells(OutRow, 1) = SummaryTable.Cells(r, 1) OutputRange.Cells(OutRow, 2) = SummaryTable.Cells(1, c) OutputRange.Cells(OutRow, 3) = SummaryTable.Cells(r, c) OutputRange.Cells(OutRow, 3).NumberFormat = SummaryTable.Cells(r, c).NumberFormat OutRow = OutRow + 1 Next c Next r End Sub 

你会得到这样一个平坦的表格:

在这里输入图像说明

然后,使用CONCATENATERANK来获得一列配对和排名。

在这里输入图像说明

这将是最后的结果:

在这里输入图像说明