2014-04-22 25 views
0

我有一个数据透视图,显示了字段的百分比作为值,但我希望标签是%和基于%的运行数量的组合上。基于原始数字的自定义图表数据标签不是%

电流:

Current

我想什么:

What I would like

的%数是容易的,因为当我通过数据的SeriesCollection环,我可以得到的值,但我无法弄清楚的是如何获取()中的数字。

我可以在原始数据集(~7000行)上做一个countif来获取数字,但这意味着我需要两行轴项目的当前值。 Axis items

那么,有没有当我经过的SeriesCollection点循环,以获得两个项目的价值在轴领域

例如方式当我在16.86点时,我可以得到“响应性”和“没有评论/没有响应”的值,所以我可以做的countif和数字在()

回答

0

它看起来像我得到了我自己的问题的答案。我支持通过pivotfield循环并跳过那些不需要的,然后在循环中更新点。

这里是什么,我做了一个样本:

Set WSpt = Sheets("PivotTablesSheet") 
Set pt = WSpt.PivotTables("PivotTableName") 
Set pf = pt.PivotFields("FieldName") 
F = pt.PivotFields("FilterName").CurrentPage.Name 'if Needed 
Vals = Cht.SeriesCollection(1).Values 'Values of the chart because you can not work with them directly :(
Set LR = WSpt.Cells(pf.DataRange.Row, pf.DataRange.Column) 'First Cell in Field DataRange 

'loop through cells in FieldName DataRange 
For i = 1 To pf.DataRange.Cells.Count 
    'Put in check to see if the cell that was currently being checked was part of the primary field or the secondary one (only needed because I had a multi-level field setup 
    On Error Resume Next 
    tmp = pt.PivotFields("Main").PivotItems(LR.Value) 
    If Err.Number = 0 Then 
     Q = LR.Value 
     Set LR = LR.Offset(1, 0) 
     i = i - 1 
    Else 
     RC = LR.Value 
     Set LR = LR.Offset(1, 0) 
     'change formula to get the number value based on if the "(All)" option was selected or if just some items in the table need to be counted 
     If F = "(All)" Then 
      'Save Results of CountIF in the NUM variable 
      Num = Application.WorksheetFunction.CountIfs(Sheets("DataSheet").Range(Sheets("DataSheet").ListObjects("DataTBL").ListColumns("Main").DataBodyRange.Address), Q, _ 
       Sheets("Data").Range(Sheets("DataSheet").ListObjects("DataTBL").ListColumns("FieldName").DataBodyRange.Address), RC) 
     Else 
      Num = Application.WorksheetFunction.CountIfs(Sheets("Data").Range(Sheets("DataSheet").ListObjects("DataTBL").ListColumns("FilterName").DataBodyRange.Address), F, _ 
       Sheets("Data").Range(Sheets("DataSheet").ListObjects("DataTBL").ListColumns("Main").DataBodyRange.Address), Q, _ 
       Sheets("Data").Range(Sheets("DataSheet").ListObjects("DataTBL").ListColumns("FieldName").DataBodyRange.Address), RC) 
     End If 
     Cht.SeriesCollection(1).Points(i).DataLabel.Text = FormatPercent(Vals(i), 1) & " (" & Num & ")" 
     Cht.SeriesCollection(1).Points(i).DataLabel.Orientation = xlUpward 
    End If 
Next i 
End Sub 
0

你可以点击标签,按=键,然后将其指向单元格,它将显示您指向的单元格的值。你应该做一个帮手单元来做到这一点,以你想要的方式来设置它的值。

+0

问题是,数据透视表和图表都需要在飞行中进行更新,这就是为什么我去VBA路线。 –

+0

阅读失败。我为我的房子蒙羞。 – Bmo

+0

不用担心,我在考虑从1到点数的循环,然后尝试从系列集合中的XValues获取数据可能会起作用,但我无法从XValues中获取正确读取的数据。 :( –

相关问题