我有大量数据必须在 Excel 中进行分析(我意识到这在数据库中会容易得多)。每个订单项都有一个 T/F 指示器,用于指示其在给定类别中的成员资格,我希望获得每个类别跨月份的数量和价格的相关性。我所说的数据量是一次 8-30k 条记录。我们在我的办公室使用 Excel 2010
示例数据:
State | Cat.1 | Cat.2 | Cat.3 | TimeStamp | Volume | Price
WA | TRUE | FALSE | FALSE | 01/31/13 12:00 | 113.1 | 35.64
WA | TRUE | TRUE | FALSE | 01/31/13 13:00 | 65.2 | 32.52
FL | TRUE | FALSE | TRUE | 01/31/13 02:00 | 78.9 | 36.37
FL | TRUE | TRUE | FALSE | 01/31/13 23:00 | 113.9 | 39.39
理想情况下,我想要的是一个数据透视表,它将关联州、类别 1、年份和月份的给定组合的数量和价格。
现在我有一个计算字段,其公式为:=correl(Volume,Price) 然而,该字段对于每种情况都会返回#DIV/0,但是如果我双击查看适用的数据,我可以手动执行 correl() 并且它工作正常。
任何帮助将不胜感激!
不确定我是否完全理解您的问题,但听起来您想根据其他一些列的值进行关联。因此,我假设如果您在标题行上使用自动过滤器,并且可以过滤所需的状态和类别,则只需关联可见值即可。您可能需要两个额外的列,其中 =MONTH( ) 和 =YEAR( ) 以及时间戳。
我在下面编写的 UDF 将仅关联可见列,因此请转到 VBA 编辑器 (Alt F11 ) 并复制此内容,然后输入下面的公式并过滤您的列
=CorrelVisibleCells(F1:F100,G1:G100)
假设 F 和 G 是您的交易量和价格列
Public Function CorrelVisibleCells(aRange1 As Range, aRange2 As Range)
Dim aCorrelRange1()
Dim aCorrelRange2()
Dim rc As Long
Dim clCount As Long
Application.Volatile True 'This is a volatile function as changing the filter state without changing the cell reference requires a recalc
rc = aRange1.Rows.Count
ReDim aCorrelRange1(rc) 'Largest they could be, will crop at the end
ReDim aCorrelRange2(rc)
clCount = 0
For i = 1 To rc
If Not aRange1.Cells(i).EntireRow.Hidden Then ' Can't use SpecialCells(xlCellTypeVisible) in a UDF
aCorrelRange1(clCount) = aRange1.Cells(i).Value
aCorrelRange2(clCount) = aRange2.Cells(i).Value
clCount = clCount + 1
End If
Next
ReDim Preserve aCorrelRange1(clCount - 1)
ReDim Preserve aCorrelRange2(clCount - 1)
CorrelVisibleCells = WorksheetFunction.Correl(aCorrelRange1, aCorrelRange2) 'Get Excel to do the correlation on our new arrays
End Function