+ Reply to Thread
Results 1 to 25 of 25

Formula or VBA to aggreagate data from table?

  1. #1
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Formula or VBA to aggreagate data from table?

    Hi,

    how can i do aggregation based on chosen values from table?
    It is better to use code or formula?

    In source there is a source table.
    and want i want is to to get Result string:

    Screenshot_27.png

    So basically for Server1 and Location1 i have 3 numbers = 1,2 and 3 and i want get them in column Result in example1 worksheet.

    I think formula would be better here. Because VBA demands to add worksheet change event and i have a lot conditions there right now.

    Please help,
    Jacek
    Attached Images Attached Images
    Attached Files Attached Files

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

    Re: Formula or VBA to aggreagate data from table?

    PowerQuery might be the best way. I'll have a look.
    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.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  3. #3
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,416

    Re: Formula or VBA to aggreagate data from table?

    Have a look at the attached and see if it does what you want.

    Change the data in these cells and then click on Refresh All on the data ribbon to see the zone list change:

    Excel 2016 (Windows) 32 bit
    F
    G
    1
    server1 location1
    2
    server1 location1
    Sheet: Source

    Excel 2016 (Windows) 32 bit
    F
    4
    Zone
    5
    1
    6
    2
    7
    3
    Sheet: Source

    Add/amend data in the source table, then click Refresh All.
    Attached Files Attached Files

  4. #4
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: Formula or VBA to aggreagate data from table?

    thank you Ali!

    Sounds interesting. Disadvantage of this solution is that i still have to trigger refreshing PQ after changing cells.
    So i need to implement VBA...
    The same will be with pivot table (if it is possible?)

    What about formula?
    It is possible?

    Jacek

  5. #5
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,416

    Re: Formula or VBA to aggreagate data from table?

    Ah, yes, but you can automatically refresh PQ using VBA.

    So, record the refresh action, then include the code in some VBA that is triggered when there's a cell change in the source data area (worksheet change event, I believe). It's as simple as that!!!

    Please Login or Register  to view this content.
    Last edited by AliGW; 08-23-2019 at 06:47 AM.

  6. #6
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,416

    Re: Formula or VBA to aggreagate data from table?

    Courtesy of a Microsoft VBA help page, this might do it (untested):

    Please Login or Register  to view this content.
    https://docs.microsoft.com/en-us/off...o-cells-change

  7. #7
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: Formula or VBA to aggreagate data from table?

    ok thank you Ali.

    Can you provide also formula for this?
    With aggregation?

    I will test both.

    Jacek

  8. #8
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,704

    Re: Formula or VBA to aggreagate data from table?

    Put this formula in cell D2 of the Source sheet:

    =IF(AND(Table1[[#This Row],[Server]]=Example1!$A$2,Table1[[#This Row],[LocationID]]=Example1!$B$2),MAX(D$1:D1)+1,"-")

    It should automatically copy itself down and add that column to your table.

    Then you can use this formula in cell E2 of the Example1 sheet:

    =IFERROR(INDEX(Source!$C:$C,MATCH(ROWS($1:1),Source!$D:$D,0)),"")

    Copy this down as far as you think you will need.

    Hope this helps.

    Pete

  9. #9
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: Formula or VBA to aggreagate data from table?

    Hi Pete,

    thank you. Very interesting approach. It is possible to create this helpep column separated from table?

    Best,
    Jacek

  10. #10
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,704

    Re: Formula or VBA to aggreagate data from table?

    You can put it in whichever column you like (or even on another sheet), but you will need to amend the second formula so that it points to the new column instead of Source!$D:$D.

    Hope this helps, and thanks for the rep.

    Pete

  11. #11
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: Formula or VBA to aggreagate data from table?

    ok thank you ver much,

    can you please help with this Pete?
    How to do separately?

    Best Wishes,
    Jacek
    Last edited by jaryszek; 08-23-2019 at 11:19 AM.

  12. #12
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,416

    Re: Formula or VBA to aggreagate data from table?

    No rep for me - obviously not a good enough solution.

    Jacek - Pete has given very simple instructions. What went wrong when you tried to implement them?

  13. #13
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,704

    Re: Formula or VBA to aggreagate data from table?

    Okay, I've moved the helper column to column E in the Source sheet. Is that what you wanted?

    Hope this helps.

    Pete
    Attached Files Attached Files

  14. #14
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: Formula or VBA to aggreagate data from table?

    ok thank you Pete_UK.

    Yes it was straightforward but what if you want to put the list for example in different sheet and different column and cell?:
    Attachment 638803

    it will not work.
    And i can not do this in the same table and same horizontal level as table is....

    Can you please with writing aggregate formula ?

    Jacek

  15. #15
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,704

    Re: Formula or VBA to aggreagate data from table?

    Your latest attachment comes up as invalid when I try to download it. Did you try to use the Paperclip icon? It doesn't work on this forum, so use Manage Attachments from the Go Advanced button below the edit window, and follow the on-screen prompts.

    Hope this helps.

    Pete

  16. #16
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: Formula or VBA to aggreagate data from table?

    Ok,

    once again:

    Screenshot_2.png


    i simply moved it in another place in workbook. I do not want to have this as the same level of Table.

    Jacek

  17. #17
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,704

    Re: Formula or VBA to aggreagate data from table?

    I've moved the helper column into another sheet and made appropriate changes to the formulae.

    Hope this helps.

    Pete
    Attached Files Attached Files

  18. #18
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: Formula or VBA to aggreagate data from table?

    o wow thank you!!!

    i tried by my own with this one but i failed:

    =IF(AND(Table1[Server]=Example!A2;Table1[LocationID]=Example!B2);MAX(E$1:E1)+1;"-")

    This is very nice but:
    1. If i will move my table i will have an issue - because i will not know from where should i start comparing table rows.
    I think that i should have reference somehow to dynamic table instead of having addresses.
    2. I think that it should use row reference but i can not (i do not know) how to implement this...

    please help,
    Jacek

  19. #19
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: Formula or VBA to aggreagate data from table?

    Hi,

    anyone can figure out formula for this ? (for table in different places in workbook).

    Best,
    Jacek

  20. #20
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: Formula or VBA to aggreagate data from table?

    Hi,

    please help.
    No formula to aggregate this using reference to table headers and columns?

    Jacek

  21. #21
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,704

    Re: Formula or VBA to aggreagate data from table?

    I really don't understand what the problem is here. It might be better to attach a new workbook with some realistic examples of how you intend to use it. Are you really going to move the table around after setting it up?

    Pete

  22. #22
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: Formula or VBA to aggreagate data from table?

    Hi Pete,

    i moved table and i am attaching workbook.
    Thank you for help and support.

    So question is, how to refer to the table if table will be moved? (and i have the case while loading table from source - the position of tables can be changed)

    Jacek

    Screenshot_6.png
    Attached Files Attached Files

  23. #23
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,704

    Re: Formula or VBA to aggreagate data from table?

    Sorry for the delay in getting back to you. My ISP chose today to "update their infrastructure" and so the internet connection went down soon after my earlier post - at least they gave us some warning, but it has been frustrating nonetheless.

    I thought you wanted the helper column in a different sheet, so that it doesn't interfere with the Source sheet, so I have used column D in the Example sheet with this formula in D2:

    =IFERROR(IF(AND(INDEX(Table1,ROWS($1:1),1)=$A$2,INDEX(Table1,ROWS($1:1),2)=$B$2),MAX(D$1:D1)+1,"-"),"-")

    which can be copied down as far as you like. You can interrogate Table1 using the INDEX function, as "Table1" is just a named range (well, it's a bit more than that, but you can see it listed in Name Manager). The ROWS($1:1) term increments on each row that the formula is copied to, and the first INDEX term is looking specifically in column 1 of the table (shown in red) and the second one at column 2. The IFERROR term allows you to copy down beyond the number of rows in the table, in order to accommodate more data being added to the table at a later date.

    I've put the Result column in column G, and used this formula in G2:

    =IFERROR(INDEX(Table1,MATCH(ROWS($1:1),$D:$D,0)-1,3),"")

    This is very similar to before, but now we are getting the data from the 3rd column of Table1. Although these column numbers have been hard-coded in the formulae, you could easily use a MATCH function acting on the column headers.

    If you move your Table1 around by inserting/deleting rows or columns in the Source sheet, the formulae should still bring the same data back.

    Hope this helps.

    Pete
    Attached Files Attached Files

  24. #24
    Forum Contributor
    Join Date
    01-16-2014
    Location
    Poland
    MS-Off Ver
    Excel 2016-365
    Posts
    2,940

    Re: Formula or VBA to aggreagate data from table?

    o wow you are the boss!!

    thank you once again for help and support.

    Jacek

  25. #25
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,704

    Re: Formula or VBA to aggreagate data from table?

    I'm glad that we finally got to a solution that works for you.

    Thanks again for the reps.

    Pete

+ 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: 1
    Last Post: 09-08-2017, 07:30 AM
  2. Replies: 1
    Last Post: 01-08-2015, 07:02 PM
  3. I need a formula to auto popluate data in a table from another table.
    By sixsteps268 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 05-14-2013, 06:46 AM
  4. [SOLVED] Formula for copying over relevant data from one table to populate another table
    By amasson in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 04-19-2013, 06:11 AM
  5. Replies: 2
    Last Post: 04-15-2013, 07:22 AM
  6. [SOLVED] Formula for copying over relevant data from one table to populate another table
    By amasson in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 02-25-2013, 12:41 PM
  7. [SOLVED] Formula for creating a table from data from another table
    By amasson in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 02-12-2013, 09:35 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