+ Reply to Thread
Results 1 to 10 of 10

Combining data from multiple sheets (VSTACK, etc.)

  1. #1
    Registered User
    Join Date
    05-01-2020
    Location
    Massachusetts
    MS-Off Ver
    Excel for Mac 16.80 (Microsoft 365)
    Posts
    28

    Combining data from multiple sheets (VSTACK, etc.)

    Hey all... I'm still a bit of a novice when it comes to Excel's newest dynamic functions, so I'm sure there's an answer here I just haven't figured out yet.

    I have two worksheets of similar, but not exactly, structured data. My goal is to combine the data into a single "consolidated" worksheet and, ultimately, to pluck certain columns from each of the source worksheets to form this "child" table.

    I've put together a simple example in the attached spreadhseet.

    Note that in the 2022 and 2023 tables the data is structured the same, albeit with different #s of rows. Evan Brown appears in both tables. The goal is merge these tables into one, but have no duplicates ... and then sort them in a particular order. SORT(UNIQUE(VSTACK( does this perfectly. That's Example #1.

    But in Example #2, the data isn't quite the same ... the 2023 table doesn't include any badge data, so even though Mr. Brown is in both tables, his entire record is not the same in 2022 and 2023. VSTACK still works, but UNIQUE is considering the entire record, and thus duplicates Mr. Brown.

    QUESTION #1 -- How to get UNIQUE to consider column 1 (Name) only.

    In Example 3, we get close to my true data set, in that the two parent tables are structured differently. While they share two columns, they each have a unique column. Still needing to combine these two tables here, but VSTACK isn't going to do in anymore, as it puts "Committee Room" from 2023 in the same column as "Badge #" from 2022.

    QUESTION #2 -- How do you combine data from two tables with different structures?

    If Question #1 can be answered successfully, then one approach is to manually restructure the data in the parent tables so it has the same structure, and then use VSTACK to pull it to a consolidated table. But not having to take this step would be preferable.

    The reason I liked VSTACK to pull the entire table is the ability to sort off of another column other than the primary (in this case the primary column is Name, but we are sorting on Badge#). If we VSTACK just name and then use formulas to bring over the other data, this gets around the structure isssue, but causes problems sorting the VSTACK array by anything other than itself. So, final question...

    QUESTION #3 -- How do you sort a table sourced from tables with different structures, especially when the primary key is an array?

    This is Example 4, where VSTACK is used only to pull the Name and subsequent columns are pulled with formulas. But this requires that the lookup formula either a) be in hierarchal order when the data exists in both tables (column "Name") or point only to the specific parent table when the data doe not (columns "Badge #" and "Committee Room"), which isn't particular consistent or simple. And the only way I can sort it (AFAIK) is within the array itself (Name) which isn't the goal. Although I tried SORTBY vs. SORT, I could not come up with a way to get it to sort correctly. (In this simple example, getting it to sort by badge # and putting all the blanks at the beginning or end would suffice).

    Many thanks!
    Attached Files Attached Files
    Last edited by seh0872; 12-20-2023 at 09:36 PM.

  2. #2
    Forum Expert
    Join Date
    10-19-2021
    Location
    Brazil
    MS-Off Ver
    Office 365 V2401 w/ Win10 Home 64 Bit
    Posts
    2,014

    Re: Combining data from multiple sheets (VSTACK, etc.)

    I think I've done what you are asking for...

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    and

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Booth in the attached file.
    Attached Files Attached Files
    Last edited by DJunqueira; 12-20-2023 at 11:24 PM.

  3. #3
    Forum Expert
    Join Date
    02-10-2019
    Location
    Georgia, USA
    MS-Off Ver
    Office 365
    Posts
    2,842

    Re: Combining data from multiple sheets (VSTACK, etc.)

    Excellent formulas by DJunqueira. I think there might have been a copy/paste issue though for the first formula. It's correct in the file, but in the text above, something got jumbled. I believe t should have been:

    Please Login or Register  to view this content.
    And if you wanted to get rid of the 0's, you could use:

    Please Login or Register  to view this content.

  4. #4
    Forum Expert
    Join Date
    10-19-2021
    Location
    Brazil
    MS-Off Ver
    Office 365 V2401 w/ Win10 Home 64 Bit
    Posts
    2,014

    Re: Combining data from multiple sheets (VSTACK, etc.)

    Quote Originally Posted by Gregb11 View Post
    Excellent formulas by DJunqueira. I think there might have been a copy/paste issue though for the first formula.[/CODE]
    Tks Gregb11, I have a hard time translating my formulas with the new functions, the app does not translate them.

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    You have done the right fix, tks again.
    Last edited by DJunqueira; 12-21-2023 at 01:48 AM.

  5. #5
    Registered User
    Join Date
    05-01-2020
    Location
    Massachusetts
    MS-Off Ver
    Excel for Mac 16.80 (Microsoft 365)
    Posts
    28

    Re: Combining data from multiple sheets (VSTACK, etc.)

    Thanks all. More database functions to unpack. I'm going to have to study this answer a bit.

    Sometimes the challenge of posting in this formula is to try an provide an example in the simplest terms possible, and then find an answer works perfectly with the sample data but isn't directly adaptable to the actual data, which is far larger and more complex. This is the case here. Whereas in my sample file, the first two columns are the same in the source tables, that's not the case in the actual data -- and neither are the number of columns equal in each table. So, even if I adapted the VSTACK portion of the formula to, say, columns 16 and 17, where they are in table 1, in table 2 they are columns 18 and 19 ... or perhaps columns 18 and 21.

    Thus it seems like the theory of using CHOOSECOLS imbedded within XLOOKUPS is the ultimate answer, and omitting the efficient VSTACK shortcut in your answer. The problem I'm having now is when using a VSTACK inside an HSTACK,the data spills vertically from the first cell, rendering all data in the first column (other than the first cell) as #N/A, even though the data in the second column populates correctly. So, I am not adapting your HSTACK / XLOOKUP / CHOOSECOLS combination correctly.

    I'm not sure how to better represent the data than the actual file itself. To make this easier, I did remove a handful of worksheets containing a second, more complicated dataset for which this process will need to be repreated (this time with three source tables instead of two), but If I can figure this out with what's in the second attached file, I *should* be good to go. Please ignore the fact that the columns colored in green within each sub-table all happened to be in the same column distance (columns 15-18). This is a coincidence for this dataset only and is NOT the case in the next dataset (again, likely rendering that using VSTACK to pull multiple columns is likely not possible).

    Futher, the end result of the formula you posted sorts by the first column, but I was hoping for a solution that enables sorting by a different array. Maybe the real data in my file is where I should have started. Sorry for the rework.

    Source Data: USCB_Counties, USGS Counties
    Target: Consolidated_Counties

    In Consolidated, the idea is to bring the records from the source data to the target based on the unique GNIS codes. As data may be different for the same GNIS code USCB_ and USGS_, the hierarchy is USCB first, USGS second (aka if found in USCB, stop, else look in USGS). Further, the order of the resulting table should, ideally, be sorted first by STCd then by Name.

    So, the original VSTACK is sitting in th GNIS column, but I cannot figure out how to use HSTACK to bring the resulting columns over based on the GNIS column, especially when the GNIS data in the source file may not be in the same column place (again they are in this dataset, but that is not universal).

    Does this make sense?

    In layman terms:
    * For the second column of the first row, lookup GNIS 0023901 in USCB. If you find it, bring over ISOCd and place it in the State column. If you don't find it, look in USGS and do the same. If it is in neither, return nothing ("").
    * Repeat for all other columns.
    *Repeat for all other rows.
    *When done, sort the table first by STCd then by Name.

    Clearly I can do this by cutting-and-pasting the GNIS from the two source files and removing duplicates, and bring over all remaining data via lookups. This is far easier than what I'm asking, but I'm trying to learn how to do it dynamically via formulas instead as, while this dataset may not change, good practice is rarely cut-and-pasting.

    Thanks for your continued help.
    Attached Files Attached Files
    Last edited by seh0872; 12-21-2023 at 11:27 AM.

  6. #6
    Forum Expert
    Join Date
    10-19-2021
    Location
    Brazil
    MS-Off Ver
    Office 365 V2401 w/ Win10 Home 64 Bit
    Posts
    2,014

    Re: Combining data from multiple sheets (VSTACK, etc.)

    What you want to do would be much better in Power Query, including accessing the data source in the internet.

    I'll try to do both PQ and formula...

  7. #7
    Forum Expert
    Join Date
    10-19-2021
    Location
    Brazil
    MS-Off Ver
    Office 365 V2401 w/ Win10 Home 64 Bit
    Posts
    2,014

    Re: Combining data from multiple sheets (VSTACK, etc.)

    Work in progress..

    Did some PQ and formulas.


    Formula sheet USCB column Q:
    =REDUCE(T_USCB[@NAME],TRemove[Remove_list],LAMBDA(a,b,TRIM(SUBSTITUTE(a,b,""))))


    Column R:
    =LET(s,SUM((DIVIDIRTEXTO(T_USCB[@NAME]," ")=TFind[Find])*ROW(TFind[Fill])),IF(s=0,"Other",INDEX(TFind[[#All],[Fill]],s)))


    New sheet resultant of PQ, 'Consolidated_Counties (2)'

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    And
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Lets keep talking.
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    05-01-2020
    Location
    Massachusetts
    MS-Off Ver
    Excel for Mac 16.80 (Microsoft 365)
    Posts
    28

    Re: Combining data from multiple sheets (VSTACK, etc.)

    Quote Originally Posted by DJunqueira View Post
    Work in progress..

    Did some PQ and formulas.

    Lets keep talking.
    Thanks DJunqueira. As I work with this messy dataset, I keep coming at it from different angles ... in many ways because with the formula-heavy approach the demand is too great either for the way Excel allocates memory or for my computer's RAM. Either way, I keep running into walls with performance, or along the way discover another condition of the data I have to deal with that requires a different perspective. Sometimes this means that my original question becomes irrelevant to my project as I retool the approach. But please don't think you're wasting your time answering me. I'll certainly have a study of the answer because even if I've come up with a different approach for the immediate problem at hand, the answers here are very useful in understanding how to operate Excel more intelligently, and will most likely be useful to me at some other point. Frankly, solving the problem for my project is great, but just learning more about Excel is even better.

    That being said, I currently know nothing of PowerQuery and have never used it. It seems like it's worth some effort to be familiar with, although with as much data as I am working with, it maybe too much of a resource hog.

    I ended up breaking the data into smaller components and regressing to some simple VLOOKUPs to move data from one worksheet to the next. This does not provide the intelligence with the spreadsheet of how to handle duplicate data, but with the dataset made smaller, I can more easily find such issues and deal with them manually. The data eventually needed to be segregated anyway, so essentially all I've done is segregate it earlier in the process, which ultimately probably makes the process easier.

    For now, there's little more I'll do here, as I'll need to make time to begin to learn about PowerQuery and see where I can begin to utilize it. Based on the summary description provided by Microsoft ("Power Query is the data connectivity and data preparation technology that enables end users to seamlessly import and reshape data from within a wide range of Microsoft products, including Excel, Power BI, Analysis Services, Dataverse, and more."), it appears a worthwhile tool given that what I am doing is importing and reshaping data. Thanks for pointing me towards it and for your contributions on this board.

  9. #9
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,319

    Re: Combining data from multiple sheets (VSTACK, etc.)

    A VBA option

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by JohnTopley; 01-01-2024 at 03:31 PM.
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  10. #10
    Forum Expert
    Join Date
    10-19-2021
    Location
    Brazil
    MS-Off Ver
    Office 365 V2401 w/ Win10 Home 64 Bit
    Posts
    2,014

    Re: Combining data from multiple sheets (VSTACK, etc.)

    seh0872, to work with really big data Power Query is the direction to go, it is also the same tool of Power BI, so it is worth learning.
    At the beginning you don't need to use any code at all, latter you will need M code that has 'some' similarity with usual VBA code, not hard to learn.

    Have a good New Year.

+ 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. INDEX, INDIRECT, VSTACK, need help combining these
    By Sparkplug90 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 09-01-2023, 04:32 AM
  2. Combining data from multiple sheets into one
    By jamesber in forum Excel General
    Replies: 1
    Last Post: 05-23-2015, 08:24 PM
  3. Combining data from multiple other sheets onto one
    By kb9omaaj in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-09-2014, 01:11 PM
  4. Combining Data from multiple sheets...
    By FogCat in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-16-2006, 11:35 AM
  5. Combining data from multiple sheets
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-21-2005, 12:05 PM
  6. [SOLVED] Combining data from multiple sheets
    By Ron Vetter in forum Excel General
    Replies: 1
    Last Post: 04-29-2005, 03:06 PM
  7. [SOLVED] combining data from multiple sheets
    By Allen Way via OfficeKB.com in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-05-2005, 01:06 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