Excel-数据透视图-计算开始时间和结束时间是否落入时隙

时间:2018-07-25 14:02:20

标签: excel pivot-table calculated-field slicers pivot-chart

我会尽力解释。

我有一些数据,其中包含开展活动的开始时间和时间段。 例如

Name   Start Time  Activity Length (mins)
James    08:00           45
Phil     10:10           30
Angela   10:20           50

我想在该时间段内每次活动进行时在x-axis上显示时间,在y-axis上显示计数。

我想在PivotTable中使用它,因为数据经常更改(当前保存为Excel表Table1),并且它将与连接到其他图形的切片器交互。根据上面的数据(不包括James),我在下面显示了PivotTable的外观。

例如

Time   Count
10:00  0
10:05  0
10:10  1
10:15  1
10:20  2
10:25  2
10:30  2
10:35  2
10:40  2
10:45  1
10:50  1
10:55  1
11:00  1
11:05  1
11:10  0
11:15  0
11:20  0

这很简单,没有使用countif的数据透视表:

=countifs(StartTime,"<="&A1,StartTime+(ActivityLength/1440),"<"&A1),

但是,如果数据不断变化并且需要应用多个过滤器,则看起来我将需要数据透视。 顺便说一句,我正在使用Excel 2010

1 个答案:

答案 0 :(得分:0)

详细说明过滤条件

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim ws As Worksheet
        Set ws = ActiveSheet

    Dim lastRow As Long
        lastRow = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row


    Dim tbl As ListObject
        Set tbl = ws.ListObjects(1)

        tbl.Resize ws.Range("A2:D" & lastRow)
End Sub

enter image description here

enter image description here