+ Reply to Thread
Results 1 to 27 of 27

Trying to group pivot data into weekly buckets

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    02-04-2015
    Location
    Dallas,Texas
    MS-Off Ver
    excel 2013
    Posts
    191

    Trying to group pivot data into weekly buckets

    Please refer to tab "UHC by State"

    I am trying to take the pivot data on the left and group them into Weekly buckets(ex. Week 1, 2, 3, etc). I provided an example in the tab. The start date for the range would be 1/1/2017 and end date 7/17/2017. The dates would exclude weekends for example Week 1 would be 1/2/2017 to 1/6/2017 and so on.

    If there is another idea that is fine too.


    Thank you.
    Last edited by AliGW; 07-28-2017 at 02:47 AM. Reason: Attachment removed - contains sensitive information.

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2504 (Windows 11 Home 24H2 64-bit)
    Posts
    90,658

    Re: Trying to group pivot data into weekly buckets

    I have removed your attachment as it contains sensitive information that should not be shared on a public forum.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  3. #3
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: Trying to group pivot data into weekly buckets

    I have asked a Moderator to remove your attachment. She has done so. Within a very few seconds I was able to access a list of names of real people. Not a good idea.

    To your Q. I have a dislike of Pivot Tables. I prefer formulae. I have reattached the underlying raw data with ALL information except date, UHC plan, state and approval REMOVED.

    One thing is obvious already, that one one day (never mind one week) MULTIPLE states can have approved / non-approved admissions.

    So exactly how do you want the results presented?
    Attached Files Attached Files
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU

  4. #4
    Forum Contributor
    Join Date
    02-04-2015
    Location
    Dallas,Texas
    MS-Off Ver
    excel 2013
    Posts
    191

    Re: Trying to group pivot data into weekly buckets

    My apologies everyone, I will be more mindful of sensitive data when uploading xls.

    Glenn,

    Thank you for ordering the data by date. So pretty much I just want buckets of week 1, 2, 3 etc maybe for example in column A week 1 will correspond to a range of 1/2/2017 to 2/6/2017, so row 2 will get picked up in this range and return week 1. Week 2 range is 1/9/2017 to 1/13/2017 but there are no dates in this range so nothing will get picked up and so on. There should be a total of 24 weeks, and the date ranges will exclude weekends as you can see from the ranges.

    Please let me know if this is unclear.

    Thanks

  5. #5
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: Trying to group pivot data into weekly buckets

    can you modify the sheet that I posted to show a week of expected results. So, if there are 3 states in week 1 with approved admissions EXACTLY what do you want to see and whhere do you want to see it???

  6. #6
    Forum Contributor
    Join Date
    02-04-2015
    Location
    Dallas,Texas
    MS-Off Ver
    excel 2013
    Posts
    191

    Re: Trying to group pivot data into weekly buckets

    Glenn,

    Here you go.

    Thanks,

    Pigment01

  7. #7
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2504 (Windows 11 Home 24H2 64-bit)
    Posts
    90,658

    Re: Trying to group pivot data into weekly buckets

    It would be really helpful if you could add a manual mock-up of the sort of thing you want to see in the file Glenn shared.

    You do not need to apologise to us about the file: you just need to hope that nobody unscrupulous got to it before Glenn and I did. For what it's worth, out of respect to those named in it, I didn't open it before deleting it. Letting this sort of sensitive data into the public domain without consent could land you in a lot of hot water, so do please be very careful in future. Always remember to change or obfuscate sensitive data.

  8. #8
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: Trying to group pivot data into weekly buckets

    You can try filter Referral Date in you PivotTable by This week, Last Week etc... check Date filter. Also you can define your own Custom filter. (Tab UHC by State)

    eg. This week

    thisweek.jpg
    Last edited by sandy666; 07-28-2017 at 10:54 AM.

  9. #9
    Forum Contributor
    Join Date
    02-04-2015
    Location
    Dallas,Texas
    MS-Off Ver
    excel 2013
    Posts
    191

    Re: Trying to group pivot data into weekly buckets

    Glenn,

    Here you go.

    Pigment01
    Last edited by AliGW; 08-09-2017 at 11:26 AM. Reason: Attachment removed at OP's request to protect sensitive data.

  10. #10
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: Trying to group pivot data into weekly buckets

    That's not at all like the result structure that you had originally wanted...

    Then what you had wanted was like this (but with only one stae per cell).

    So please supply a result template, assuming thta this picture does NOT meet your needs.

    Untitled.jpg

  11. #11
    Forum Contributor
    Join Date
    02-04-2015
    Location
    Dallas,Texas
    MS-Off Ver
    excel 2013
    Posts
    191

    Re: Trying to group pivot data into weekly buckets

    I am open to ideas on the data layout and what you have shown me in the picture suffice, but could I use this template moving forward?

    Also in the area where it says "no referral" in my original file I do not have that in the pivot table?

  12. #12
    Forum Contributor
    Join Date
    02-04-2015
    Location
    Dallas,Texas
    MS-Off Ver
    excel 2013
    Posts
    191

    Re: Trying to group pivot data into weekly buckets

    Also we can add that template as an additional piece which would be great.

  13. #13
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: Trying to group pivot data into weekly buckets

    I got all of the data (including names, etc) from your pivot table... Do you want lost referrals as well, or just approved and not approved. BtW, to get all the states in one cell will require the use of VBA. is that OK??

  14. #14
    Forum Contributor
    Join Date
    02-04-2015
    Location
    Dallas,Texas
    MS-Off Ver
    excel 2013
    Posts
    191

    Re: Trying to group pivot data into weekly buckets

    Gotcha! Just approved and not approved will be fine. And yes VBA is fine too. Is this something I can use moving forward in different cycles since you are automating it?

  15. #15
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: Trying to group pivot data into weekly buckets

    So.

    VBA code, pasted into a module:

    Public Function ConcatAll(ByVal varData As Variant, Optional ByVal sDelimiter As String = vbNullString, Optional ByVal bUnique As Boolean = False) As String
       
        Dim DataIndex As Variant
        Dim strResult As String
        
        If IsArray(varData) _
        Or TypeOf varData Is Range _
        Or TypeOf varData Is Collection Then
            
            For Each DataIndex In varData
                If Len(DataIndex) > 0 Then
                     If bUnique = True Then
                          If InStr(1, "||" & strResult & "||", "||" & DataIndex & "||", vbTextCompare) = 0 Then
                           trResult = strResult & "||" & DataIndex
                        End If
                    Else
                        strResult = strResult & "||" & DataIndex
                    End If
                End If
            Next DataIndex
            
            strResult = Replace(Mid(strResult, 3), "||", sDelimiter)
            
        Else
            strResult = varData
        End If
        
        ConcatAll = strResult
        
    End Function
    Helper column in AA, copied down:
    =WEEKNUM(T2)

    Array Formula in sheet2, B3, copied down:
    =concatall(IF(Sheet1!$AA$2:$AA$90=Sheet2!$A3,Sheet1!$F$2:$F$90,""),", ")

    Formula in sheet 2 C3, copied across and down:
    =COUNTIFS(Sheet1!$W:$W,Sheet2!C$2,Sheet1!$AA:$AA,Sheet2!$A3)



    Array Formulae are a little different from ordinary formulae in that they MUST be confirmed in the FIRST CELL ONLY by pressing CTRL+SHIFT+ENTER to activate the array, not just ENTER. After that, the array can be dragged down as normal, to cover the desired range.

    You will know the array is active when you see curly brackets { } - or "curly braces" for those of you in the USA, or "flower brackets" for those of you in India - appear around the outside of your formula. If you do not use CTRL+SHIFT+ENTER you will (almost always) get an error message or an incorrect answer. Press F2 on that cell and try again.

    Don't type the curly brackets yourself - it won't work...

    see sheet.
    Attached Files Attached Files

  16. #16
    Forum Contributor
    Join Date
    02-04-2015
    Location
    Dallas,Texas
    MS-Off Ver
    excel 2013
    Posts
    191

    Re: Trying to group pivot data into weekly buckets

    This is beyond my skill level, but very good job! Could you walk me through how you created the VBA code and the logic around it?

    And does the "Helpercolumn AA" denote a week number?

  17. #17
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: Trying to group pivot data into weekly buckets

    See if it does wht you want. Merely delete the columns you don't want.

  18. #18
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: Trying to group pivot data into weekly buckets

    AA. Yes. It returns a week number.

    TbH, I didn't create the code. I shamelessly plagiarised it from another user here. I'm hopeless with VBA and use it like a drunk uses a street light: for support and not for illumination.

    Regarding the original pivot table: do you know how to get the raw data (sheet1) from it?

  19. #19
    Forum Contributor
    Join Date
    02-04-2015
    Location
    Dallas,Texas
    MS-Off Ver
    excel 2013
    Posts
    191

    Re: Trying to group pivot data into weekly buckets

    Yes, I understand pulling the raw and creating a pivot table. I had a teammate that forwarded that data to me so I didn't look at the raw data.

    As far as the formulas, could break down the logic behind it? for example in Sheet2. . sorry I am still learning with Excel. Formulas in B3 and C3 and how it works and the relationships here?

  20. #20
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: Trying to group pivot data into weekly buckets

    Re the VBA. Right click on the tab name. Select View code. click on module 1. Voila...

  21. #21
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: Trying to group pivot data into weekly buckets

    Re the pivot. I'll be back in a mo. I'll have to find your original attachment from my Recycle Bin...

  22. #22
    Forum Contributor
    Join Date
    02-04-2015
    Location
    Dallas,Texas
    MS-Off Ver
    excel 2013
    Posts
    191

    Re: Trying to group pivot data into weekly buckets

    Sounds good, thanks!

  23. #23
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: Trying to group pivot data into weekly buckets

    Click on any cell in the pivot table on "UHC by State" Hopefully you'll see pivot table fields on the right of your screen. if not, Go: Analyse/show/field list.

    Doiwn near the bottom of the pivot table fields, drag referral dates into the Σ-values box. If it DOESN'T say count of referrals, click thedown arrow in referrals, go to value field settings and selet count of referrals.

    Then... Design/subtotals/show all subtotals at bottom of group.

    then click on th etiny minus sign in the box to the left of UHC on your picvot table. All being well, it will show 80 in the column count of referral dates. Double click the 80 and a new sheet will open up.

    It contains all the confidential stuff. I deleted all except the bits I needed. That was what I posted way back at the start of this saga.

    Clear as mud??

  24. #24
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2504 (Windows 11 Home 24H2 64-bit)
    Posts
    90,658

    Re: Trying to group pivot data into weekly buckets

    Quote Originally Posted by Glenn Kennedy View Post
    I'm hopeless with VBA and use it like a drunk uses a street light: for support and not for illumination.
    rotfl.gif

    ............................

  25. #25
    Forum Contributor
    Join Date
    02-04-2015
    Location
    Dallas,Texas
    MS-Off Ver
    excel 2013
    Posts
    191

    Re: Trying to group pivot data into weekly buckets

    Also the VBA code where did you put it in? I am not seeing it when I "view macros"?

  26. #26
    Forum Contributor
    Join Date
    02-04-2015
    Location
    Dallas,Texas
    MS-Off Ver
    excel 2013
    Posts
    191

    Re: Trying to group pivot data into weekly buckets

    Sorry last question, how did you reqroup all the data very quickly from the pivot table data and order the dates?

    Thanks

  27. #27
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: Trying to group pivot data into weekly buckets

    B3:

    =concatall(IF(Sheet1!$AA$2:$AA$90=Sheet2!$A3,Sheet1!$F$2:$F$90,""),", ")

    Red: If the weeknumber in AA matches the value in A3
    Green: return the states,
    Cyan: If no matches return a blank
    Orange: separate the values by a comma and a space
    Black concatentate the whole lot into a single cell. This bit is the bit that uses VBA.


    C3:
    =COUNTIFS(Sheet1!$W:$W,Sheet2!C$2,Sheet1!$AA:$AA,Sheet2!$A3)

    Red: count the values in column W
    Green: that are equal to "Approved"
    Cyan and where the weeknumber
    Orange: Is equal to the value in A3

+ 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. Replies: 2
    Last Post: 05-14-2017, 01:40 PM
  2. [SOLVED] Transforming data from Monthly to Weekly buckets
    By tomjoe in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 02-21-2017, 10:53 AM
  3. [SOLVED] Formula to Group analytical data imputed daily into daily weekly and monthly analysis.
    By tianasamour in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 04-13-2015, 06:10 PM
  4. Replies: 1
    Last Post: 04-13-2015, 04:38 PM
  5. need dates to show as monthly buckets which i can then put in pivot table
    By eugierom in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-19-2013, 12:30 PM
  6. Replies: 6
    Last Post: 06-05-2012, 12:14 PM
  7. Data Buckets (in a range)
    By salireza in forum Excel General
    Replies: 1
    Last Post: 08-14-2006, 03:50 AM

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