【问题标题】:Correlation in Excel Pivot TableExcel 数据透视表中的相关性
【发布时间】:2013-04-24 22:40:45
【问题描述】:

我有大量数据必须在 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

理想情况下,我想要一个数据透视表,它将状态、Cat.1、年份和月份的给定组合关联交易量和价格。

现在我有一个带有公式的计算字段:=correl(Volume,Price) 然而,该字段为每个场景返回#DIV/0,但如果我双击查看适用的数据,我可以手动执行 correl() 并且它工作正常。

任何帮助将不胜感激!

【问题讨论】:

    标签: excel excel-2010 pivot-table


    【解决方案1】:

    不确定我是否完全理解您的问题,但听起来您想根据其他一些列的值进行关联。因此,我假设如果您在标题行上使用自动过滤器,并且您可以过滤您想要的状态和类别,您就可以关联可见值。您可能需要两个带有 =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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-14
      • 1970-01-01
      • 1970-01-01
      • 2011-01-18
      • 1970-01-01
      相关资源
      最近更新 更多