+ Reply to Thread
Results 1 to 6 of 6

Combining value count from multiple columns in pivot table

  1. #1
    Registered User
    Join Date
    01-29-2013
    Location
    Texas, USA
    MS-Off Ver
    Excel 2007
    Posts
    3

    Combining value count from multiple columns in pivot table

    Hello everyone. I'm new here. I've been scouring the threads for an answer to this and I apologize if it's already been explained.

    My issue is that I have a very large data set where the same value may occur in multiple columns. I need to create a pivot chart, or possibly find another solution, that allows me to track the number of times the value occurs within a date range.

    Something like this but I need it to tell me total # of each fruit purchased for that month.

    Shopper date product 1 product 2 product 3
    jim 1/31/2013 apple banana orange
    jill 2/13/2013 banana orange apple
    bob 2/4/2013 apple orange banana
    jill 1/31/2013 apple banana null
    joe 2/13/2013 orange apple banana
    betty 2/4/2013 banana orange apple
    claire 1/31/2013 apple null null
    bob 2/13/2013 banana null null


    Here is the example data file.

    Thank you in advance. Any assistance is appreciated.
    pivot grouping example.xlsx

  2. #2
    Registered User
    Join Date
    10-25-2012
    Location
    California, USA
    MS-Off Ver
    Excel 2007
    Posts
    71

    Re: Combining value count from multiple columns in pivot table

    A better solution may be the use of the CountIf function. Attached is your spreadsheet with the example of this function.

    pivot_grouping_example(solution).xlsx

  3. #3
    Registered User
    Join Date
    01-29-2013
    Location
    Texas, USA
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Combining value count from multiple columns in pivot table

    I was thinking that might be the case...
    Unfortunately in my real database, which I can't share due to sensitivity, there could be hundreds of product types. It will take a while to set up countif and try to account for all unique values. Also I need to group the results by month.
    Is there anything else that might work where it will classify all matching values without my having to specify?
    Last edited by AFsimRA; 02-01-2013 at 10:56 AM.

  4. #4
    Registered User
    Join Date
    10-25-2012
    Location
    California, USA
    MS-Off Ver
    Excel 2007
    Posts
    71

    Re: Combining value count from multiple columns in pivot table

    You are at the point where it almost makes sense to switch from using an Excel spreadsheet to an actual database like Access. One possibility is to change the format of your data entry. If you condense the product columns and assign each shopper and date, you can convert it to a pivot table easily.

    Here is an example.pivot_grouping_example(solution).xlsx

  5. #5
    Forum Contributor ptm0412's Avatar
    Join Date
    04-16-2008
    Location
    Vietnam
    MS-Off Ver
    Office 2003 and 2007
    Posts
    129

    Re: Combining value count from multiple columns in pivot table

    A Pivot table can be created only if the data set is in standard structure. That mean your data must be like this:

    Shopper Date Product
    Jim 31/01/2013 apple
    Jim 31/01/2013 Banana
    Jim 31/01/2013 Orange

    Your real Data is not at that standard, and it may has too many rows and columns to be converted.
    So I make a short VBA code to convert Data to standard structure.

    PHP Code: 
    Sub ArrangeData()
    Dim SArrRArr
    Dim RwC 
    As LongColC As Long
    With Sheet1
    .Range("Data")
        
    SArr = .Value
        RwC 
    = .Rows.Count
        ColC 
    = .Columns.Count
    End With
    ReDim RArr
    (1 To RwC ColC1 To 3)
    For 
    1 To RwC
        
    For 3 To ColC
            
    If SArr(ij) <> "null" Then
                s 
    1
                RArr
    (s1) = SArr(i1)
                
    RArr(s2) = SArr(i2)
                
    RArr(s3) = SArr(ij)
            
    End If
        
    Next
    Next
    With Sheet2
        
    .Range("A2:c" & .Range("c30000").End(xlUp).Row 1).ClearContents
        
    .Range("A2").Resize(s3).Value RArr
        
    .Range("A1").Resize(13).Name "Data1"
        
    .Select
        
    .PivotTables(1).PivotCache.Refresh
    End With

    End Sub 
    This code can work even if your data includes 10 000 rows and 256 columns. This amount can be adjusted.
    Then I make a pivot table to count the product grouping by kind of product.
    You can group by date, really.

    PS:
    you have a "banana " (with an extra space) at the end, so pivot table separate banana into 2 rows.
    Attached Files Attached Files
    Last edited by ptm0412; 02-01-2013 at 12:11 PM.
    Oldman Chatting: [email protected] Mailing: [email protected]

  6. #6
    Registered User
    Join Date
    01-29-2013
    Location
    Texas, USA
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Combining value count from multiple columns in pivot table

    Thanks everyone. I think the best solution is going to be to reorganize the data. I was hoping not to have to, but ultimately to reduce reporting error it seems this is my best solution.

    Thank you for all of your help!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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