+ Reply to Thread
Results 1 to 12 of 12

Match Row Count by Key Column - Two Tables

  1. #1
    Forum Contributor NewYears1978's Avatar
    Join Date
    03-15-2010
    Location
    Forney, TX
    MS-Off Ver
    Excel 2016
    Posts
    962

    Match Row Count by Key Column - Two Tables

    Hey all, hope you're having a nice week.

    I have two tables on a sheet that are the same (well the layout). However in the second table the key value (First column) appears more times than in the first table. I am trying to match the number of rows for each unique value so add blank rows into the first table.

    I have tried a separate table with the counts of number of rows to add then using VBA but that would crash. I tried PowerQuery but couldn't figure out how to get it how I need it. I tried pivot tables. I am at my end here.

    I am attaching a sample sheet with small set of data, keep in mind the real set is very large. The desired result is on the second tab.

    Thanks in advance!
    Attached Files Attached Files

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2504 Win 11
    Posts
    24,669

    Re: Match Row Count by Key Column - Two Tables

    See attached and advise if this works for you in PQ.
    Attached Files Attached Files
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Forum Contributor NewYears1978's Avatar
    Join Date
    03-15-2010
    Location
    Forney, TX
    MS-Off Ver
    Excel 2016
    Posts
    962

    Re: Match Row Count by Key Column - Two Tables

    Quote Originally Posted by alansidman View Post
    See attached and advise if this works for you in PQ.
    This looks similar to something I tried but failed in, going to give it a look and see if it looks correct (on glance it does).
    I assume those first rows with nothing beside them means those had no matching rows in the second table?

    Thanks so much, I will report back once I have a chance to look into it further later.

  4. #4
    Forum Contributor NewYears1978's Avatar
    Join Date
    03-15-2010
    Location
    Forney, TX
    MS-Off Ver
    Excel 2016
    Posts
    962

    Re: Match Row Count by Key Column - Two Tables

    So this almost worked, not sure if I did something wrong. On my left side (Syspro ID) the number is appearing in the last blank instead of the first. See attached image.

    My tables were named LeftTable and RightTable (I know, original) and my query looked like this:

    Please Login or Register  to view this content.
    Thanks for your help

    (I did rename my tables to the same Table1 and Table2 and use your exact query, with the same results. Not sure why it's different. In your sample file they are indeed in the right order that I want)

    I can see why the left is a little off. It's matching the SKU and putting the row on the same line as the matching SKU - which unfortunately doesn't quite work. I need the start of rows to start with the Syspro ID so it's easy to compare one to the other (data from one table to the other)

    I also tried
    Please Login or Register  to view this content.
    But then in the left side data it just fills the same data from the row across all blanks til the next Unique Syspro ID.

    Okay I think I got it now by sorting both Syspro ID columns =D

    Please Login or Register  to view this content.
    Sorry for all the rambling lol.
    Attached Images Attached Images
    Last edited by NewYears1978; 01-26-2024 at 10:10 AM.

  5. #5
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2504 Win 11
    Posts
    24,669

    Re: Match Row Count by Key Column - Two Tables

    Glad to hear it worked out. Thanks for the Rep

  6. #6
    Forum Contributor NewYears1978's Avatar
    Join Date
    03-15-2010
    Location
    Forney, TX
    MS-Off Ver
    Excel 2016
    Posts
    962

    Re: Match Row Count by Key Column - Two Tables

    Funny - tried to reproduce this in a second file and can't get them to sort properly again =D

  7. #7
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2504 Win 11
    Posts
    24,669

    Re: Match Row Count by Key Column - Two Tables

    Post a representative example of the second file and see if we can resolve.

  8. #8
    Forum Contributor NewYears1978's Avatar
    Join Date
    03-15-2010
    Location
    Forney, TX
    MS-Off Ver
    Excel 2016
    Posts
    962

    Re: Match Row Count by Key Column - Two Tables

    Here's a new sample.

    I tried hours to get this to work and cannot. It's so weird because the result works in one of my files, but in a second IDENTICAL file that I did the same exact process (I even just copied the exact queries out of it), it doesn't work. They don't sort. I get all the blank rows first instead, next to the none blank rows - instead of the data next to each other.
    Attached Files Attached Files
    Last edited by NewYears1978; 01-30-2024 at 09:22 AM.

  9. #9
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 365 version 2501
    Posts
    18,817

    Re: Match Row Count by Key Column - Two Tables

    I believe that the difference is that Alan saved queries to table1 and table2 as connections only whereas you didn't.
    See if Merge2, produced from the table1 (2) and table2 (2) connections, is showing the expected results.
    Note that I don't believe that there are any records from table2 that match both Syspro ID and SKU from table1.
    Let us 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.

  10. #10
    Forum Contributor NewYears1978's Avatar
    Join Date
    03-15-2010
    Location
    Forney, TX
    MS-Off Ver
    Excel 2016
    Posts
    962

    Re: Match Row Count by Key Column - Two Tables

    The SKUS are not supposed to match. I might not have been clear on that. The SKUS from Table1 are based off a list of legacy skus and the second list are other skus that were not those legacy skus.

    So in Merge2 the results are also not correct.

    Yesterday I was finally able to get a VBA macro working that sorted this out onto a new sheet the way I needed so I am all good now. Still a little mindblown on the PQ stuff though and why it worked one time but doing it again the same way another time did not work..haha.

    Not sure if doing a table as a connection or not matters, the data is still the same so the merge query should be the same regardless, right?

    Thanks all for the assist!

  11. #11
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 365 version 2501
    Posts
    18,817

    Re: Match Row Count by Key Column - Two Tables

    When matching only the ID's in PQ this is the result.
    Let us know if you have any questions.

  12. #12
    Forum Contributor NewYears1978's Avatar
    Join Date
    03-15-2010
    Location
    Forney, TX
    MS-Off Ver
    Excel 2016
    Posts
    962

    Re: Match Row Count by Key Column - Two Tables

    Quote Originally Posted by JeteMc View Post
    When matching only the ID's in PQ this is the result.
    Let us know if you have any questions.
    Yes, this is the original way I did it but this copies down the line above data over all blanks. It's close but should leave blanks =D

+ 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. count a column value if 2 other column conditions match
    By redJohn89 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-07-2021, 04:48 PM
  2. Replies: 1
    Last Post: 08-10-2021, 02:08 AM
  3. [SOLVED] Match First 2 columns of 2 tables, if match return data from 3rd Column
    By ManateeProfanity in forum Excel General
    Replies: 5
    Last Post: 06-27-2021, 12:14 AM
  4. [SOLVED] Count Unique Values with Partial Match one column exact match another column
    By carsto in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 07-30-2019, 09:56 AM
  5. [SOLVED] Count number of unique values in Column A that match a term in Column B
    By frsaxon in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-29-2016, 07:22 AM
  6. Replies: 2
    Last Post: 07-18-2015, 05:19 PM
  7. Find out count of Records in column A , B and C for different Tables of data
    By rampulaparthi in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-11-2013, 04:44 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