+ Reply to Thread
Results 1 to 5 of 5

Pivot table counts visits by month when one visit has multiple lines

  1. #1
    Registered User
    Join Date
    10-22-2013
    Location
    Victoria, TX
    MS-Off Ver
    Excel 2010
    Posts
    28

    Pivot table counts visits by month when one visit has multiple lines

    Here is the issue I have. We currently have multiple facilities that receive regulatory visits. During these visits they may get anywhere from 0 - 30 deficiencies. I need to set up a report (and I'm not even positive a pivot table would work) that lists the number of visits by facility and also one that shows visit by month. The problem is that the only way I've figured out to capture each deficiency (so I can also put them in a pivot table also) is to list each deficiency separately on a line. But, when I want to count visits by facility, it counts each time there is a date in the Date column. Does anyone know of a way around this? I have attached a sample of my source.

    Thanks,
    Brooke
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,567

    Re: Pivot table counts visits by month when one visit has multiple lines

    To get a count of unique visits add a helper column (Visits) to the source data with the formula:
    Please Login or Register  to view this content.
    Your Pivot Table would then have row labels of Facilities and Visits, with the subtotals and grand totals turned off and change count of Visits to Sum of Visits. It assumes that on 2/4/16 the EBL got two visits, one annual and the other C/O; S/R If that is not the case and only the date matters, change the formula to:
    Please Login or Register  to view this content.
    To get the visits by month the row labels are date and facility with the dates grouped by month and the subtotals and grand totals turned off.
    Here is a copy of your file with the helper column and pivot tables applied: Copy of Pivot Table Sample.xls
    Let me know if you have any questions.
    Consider taking the time to add to the reputation of everybody that has taken the time to respond to your query.

  3. #3
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Pivot table counts visits by month when one visit has multiple lines

    I'm going to take a slightly different approach. I am not assuming that the Facilities are in order, and that a visit consists of the combination of the facility name and the date of the visit. So I am using two helper columns:

    The first is called composite. Whenever you need to evaluate a row of data based on several criteria, one way to do it is to use what I call a "Composite Key" - this isn't an official Excel term, but it is analogous to composite keys in databases. The composite key is the concatenation of those columns that make the record unique, in this case, the facility name and date. =A2&":"&B2.

    I usually put a delimiter between the pieces of the composite key to make it more readable. It doesn't matter that the date is displayed as its numerical equivalent.

    The second helper column I call Unique and it has the formula: =MATCH(F2,F:F,0)=ROW(). This formula looks at the composite key on the row and compares it to all the other composite keys on the row. The MATCH portion of the formula returns the row number of the first instance of the composite key. If that happens to match the row number on which the formula is found (the ROW part), then this expression is True. Match finds that the first instance of the key is on a previous row, then this expression is false. So TRUE means the first instance of the key and FALSE is all the duplicates of the key.

    This method works regardless of whether the list is sorted.

    I then set up the pivot table so the report filter is the newly-created Unique column and the rows are Date (Grouped by Month) and the values is the count of the facilities.

    One question. If you have Excel 2010 then why are you still using *.xls format?
    Attached Files Attached Files
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

  4. #4
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Pivot table counts visits by month when one visit has multiple lines

    I'm going to take a slightly different approach. I am not assuming that the Facilities are in order, and that a visit consists of the combination of the facility name and the date of the visit. So I am using two helper columns:

    The first is called composite. Whenever you need to evaluate a row of data based on several criteria, one way to do it is to use what I call a "Composite Key" - this isn't an official Excel term, but it is analogous to composite keys in databases. The composite key is the concatenation of those columns that make the record unique, in this case, the facility name and date. =A2&":"&B2.

    I usually put a delimiter between the pieces of the composite key to make it more readable. It doesn't matter that the date is displayed as its numerical equivalent.

    The second helper column I call Unique and it has the formula: =MATCH(F2,F:F,0)=ROW(). This formula looks at the composite key on the row and compares it to all the other composite keys in the column. The MATCH portion of the formula returns the row number of the first instance of the composite key. If that happens to match the row number on which the formula is found (the ROW part), then this expression is True. Match finds that the first instance of the key is on a previous row, then this expression is false. So TRUE means the first instance of the key and FALSE is all the duplicates of the key.

    This method works regardless of whether the list is sorted.

    I then set up the pivot table so the report filter is the newly-created Unique column and the rows are Date (Grouped by Month) and the values is the count of the facilities.

    One question. If you have Excel 2010 then why are you still using *.xls format?

  5. #5
    Registered User
    Join Date
    10-22-2013
    Location
    Victoria, TX
    MS-Off Ver
    Excel 2010
    Posts
    28

    Re: Pivot table counts visits by month when one visit has multiple lines

    Thank you so much! You are a genius. It worked like charm. And, thank you very much for explaining it so that I could understand it and apply it in the future!

    I still use .xls because our IT department told us to due to other computers not being updated and complaints re: compatibility.

    Thanks again!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Finding multiple lines of information in a pivot table
    By bobmanboom in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 01-27-2016, 12:28 AM
  2. Replies: 6
    Last Post: 12-29-2015, 11:19 AM
  3. Replies: 7
    Last Post: 07-06-2015, 07:56 AM
  4. [SOLVED] Count the number of visits by visit types.
    By Marvin85 in forum Excel General
    Replies: 8
    Last Post: 10-02-2014, 05:19 PM
  5. Replies: 3
    Last Post: 07-28-2014, 03:48 AM
  6. Replies: 2
    Last Post: 05-08-2013, 04:56 PM
  7. Pivot Table - Summing multiple lines
    By Merh0010 in forum Excel General
    Replies: 1
    Last Post: 07-15-2010, 02:29 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1