+ Reply to Thread
Results 1 to 30 of 30

Counting between two tables

  1. #1
    Forum Contributor
    Join Date
    11-28-2011
    Location
    St. Louis, Missouri
    MS-Off Ver
    Excel 2007 & 2013
    Posts
    129

    Counting between two tables

    What I am looking to do is be able to have two different tables, one a mailed customer list and the second the sold customer list.

    In the first table I have these columns:

    State
    Car Year
    Car Make

    Second column has the exact same columns. I have been able to make a crosstab query for just one table to show something like this:

    Acura BMW Ford
    FL 2009 20000 20000 30000
    FL 2008 10000 15000 40000

    I would like to take the the sold customer list and count those up the same way on the same table to look something like this:

    Acura Sold BMW Sold Ford Sold
    FL 2009 20000 100 20000 87 30000 246
    FL 2008 10000 150 15000 92 40000 197

    Is this possible or am I reaching to far?

    Thanks in advance!
    Last edited by ncurran217; 02-07-2012 at 08:51 PM. Reason: Marking Solved

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,888

    Re: Counting between two tables

    I am a little confused by the query results. In the first table, what do the numbers represent? Sales dollars?

    In the second table, do the large numbers represent sales and the smaller numbers units? A little bit confuse here. Perhaps an example of the data that is in the tables that gave you the results in your queries would be helpful in understanding what you are specifically trying to do. Your example is not quite clear to me.
    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
    Join Date
    11-28-2011
    Location
    St. Louis, Missouri
    MS-Off Ver
    Excel 2007 & 2013
    Posts
    129

    Re: Counting between two tables

    Sorry I tried to make a table within the post box but didn't work very well. The larger number are the units mailed out, and the smaller number are the units that actually sold. I have attached an excel sheet with how I was imagining it to show up in access.

    The results in the example file attached came from two different lists that would be two different tables within access to pull from. Let me know if I am still unclear.
    Last edited by ncurran217; 02-07-2012 at 10:12 AM.

  4. #4
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,888

    Re: Counting between two tables

    I would envision this as one table set up as follows:

    table
    ------
    RecordID (PK) Autonumber
    tState
    tYear (Year is a reserved word and may cause issues if used)
    tModel
    tMailed
    tSold


    You can then develop a cross tab query to get your results. See attached as an example of how I did it.
    Attached Files Attached Files

  5. #5
    Forum Contributor
    Join Date
    11-28-2011
    Location
    St. Louis, Missouri
    MS-Off Ver
    Excel 2007 & 2013
    Posts
    129

    Re: Counting between two tables

    That's the thing the mailed and sold are in two different tables. I cannot combine the sold and mailed into one list like that. Ill see if I can create a small database with sample info

  6. #6
    Forum Contributor
    Join Date
    11-28-2011
    Location
    St. Louis, Missouri
    MS-Off Ver
    Excel 2007 & 2013
    Posts
    129

    Re: Counting between two tables

    Try this. Thank you again for the help!

  7. #7
    Forum Contributor
    Join Date
    11-28-2011
    Location
    St. Louis, Missouri
    MS-Off Ver
    Excel 2007 & 2013
    Posts
    129

    Re: Counting between two tables

    Looking at the sample data, the sold list doesnt have much that will match up with the mailed list, only 1 sold with the criteria of State, year and make should show up.

  8. #8
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,888

    Re: Counting between two tables

    Ok you should be able to join the two tables in a query to get all the information in one location. I suggest you join the tables on the Year, State and Make. A simple inner join should work. I did notice that the Dates for the two tables are not formatted the same. You will have to change one of them so that you can join the tables. I would do it in a query. I would then use that query as a substitute for the table it represents joining it to the other table. Once you have the data all in one place, I would then create a new query (cross tab without the wizard) similar to the one I showed in the attached db. It is a bit of legwork, but once completed, it will be easy to update and maintain and give you the specific information you seek.

    Alan

  9. #9
    Forum Contributor
    Join Date
    11-28-2011
    Location
    St. Louis, Missouri
    MS-Off Ver
    Excel 2007 & 2013
    Posts
    129

    Re: Counting between two tables

    So if I combine them into one table, do I just then make a column saying Mailed or Sold? And what do you mean by "Inner Join"? Sorry have spent little time in Access and trying to work more with it as some of my files are getting to big for excel.

  10. #10
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,888

    Re: Counting between two tables

    An inner join will match the two tables where the fields that you join (by dragging from one table to the other in the Query design). Once you have them joined you will need to set them up similar to what I did in the example for a cross tab Mailed: IIf( etc.....

  11. #11
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,888

    Re: Counting between two tables

    Look at the two queries here.
    Attached Files Attached Files

  12. #12
    Forum Contributor
    Join Date
    11-28-2011
    Location
    St. Louis, Missouri
    MS-Off Ver
    Excel 2007 & 2013
    Posts
    129

    Re: Counting between two tables

    Ok I am trying to do what you have suggested, but I think I am still confused, with how to create the expression to count each record that matches the criteria. I am sorry for being a pain.

  13. #13
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,888

    Re: Counting between two tables

    No problem. Let's take it a step at a time. You have joined the two tables in a query? Now you want to have a Mailed Field and a Sold Field by car type or model type? Is this correct? In the tables you presented, I wasn't able to discern the fields containing the information you wanted to extract. Which field represented mailed info and which field represented sold info?

  14. #14
    Forum Contributor
    Join Date
    11-28-2011
    Location
    St. Louis, Missouri
    MS-Off Ver
    Excel 2007 & 2013
    Posts
    129

    Re: Counting between two tables

    I think I have the two tables joined by how I understood it from your explanation:

    Attachment 140206

    For more explanation what I am looking for is, a Mailed Field and a Sold field by Car Make, Car Year, and State. For the most part the fields are the same in each table except purchdate, which can be excluded. In the screenshot I have taken purchdate completely out of the Sold Table and rename the fields. L

  15. #15
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,888

    Re: Counting between two tables

    I could not open the attachment. Says it was invalid.

  16. #16
    Forum Contributor
    Join Date
    11-28-2011
    Location
    St. Louis, Missouri
    MS-Off Ver
    Excel 2007 & 2013
    Posts
    129

    Re: Counting between two tables

    Ok let me try reattaching.

    join.jpg

  17. #17
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,888

    Re: Counting between two tables

    I don't think you need to join the list code. If there is a list code in the AB file, does that mean that a mailing went out? And if there is a listcode in the sold table does that mean that a car was sold? If this is true, then we don't want them joined as they will be the criteria for the next step.

  18. #18
    Forum Contributor
    Join Date
    11-28-2011
    Location
    St. Louis, Missouri
    MS-Off Ver
    Excel 2007 & 2013
    Posts
    129

    Re: Counting between two tables

    Well yes and no. List Code is not a Unique Identifier. I really could just completely leave it out of both tables, but so I know which table I am adding to I kept it.

  19. #19
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,888

    Re: Counting between two tables

    I'm still trying to figure out what determines the count of mailings. Does each record in the AB table represent 1 mailing?

  20. #20
    Forum Contributor
    Join Date
    11-28-2011
    Location
    St. Louis, Missouri
    MS-Off Ver
    Excel 2007 & 2013
    Posts
    129

    Re: Counting between two tables

    Yes it does. And each record in the Sold table represents 1 sold record

  21. #21
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,888

    Re: Counting between two tables

    Ok, then. Look at the qJoinQuery. Now this runs down and not accross. If you really want it across, then we can do some gyrations.

    You will have to change the field names, as I used the earlier db with the other names.
    Attached Files Attached Files

  22. #22
    Forum Contributor
    Join Date
    11-28-2011
    Location
    St. Louis, Missouri
    MS-Off Ver
    Excel 2007 & 2013
    Posts
    129

    Re: Counting between two tables

    Ok, this looks good, but the 1 sold record is not showing up. I took model out and did it versus make, which is what I was looking for. The sold one that should show up is record 17 of the Sold Table

    and what is the qFixYear Query for?

  23. #23
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,888

    Re: Counting between two tables

    The qfixYear query was because the two tables here had the years formatted differently. One table was text and the other was integer. Needed to get them the same for the join to work. Not sure why that is not showing up. I did it a little different way. Did two aggregate queries. One on mailing and one on sales and then joined those two queries to get the final result.
    Attached Files Attached Files

  24. #24
    Forum Contributor
    Join Date
    11-28-2011
    Location
    St. Louis, Missouri
    MS-Off Ver
    Excel 2007 & 2013
    Posts
    129

    Re: Counting between two tables

    Ok so you have everything base of Model, which when I try to take model out of the equation and do it just on make (Ex. Ford, GMC, Mercury) it doesn't show up. Am I missing something that would cause it to not show up?

    And what are the differences in the Queries QMailed vs Sold and qJoinTables?

  25. #25
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,888

    Re: Counting between two tables

    the results should be the same, but I could not figure out why the mercury was not appearing in the qJoinTables as sold. So I took a different approach. I ran an aggregate query to total the mailings. I then ran an aggregate query to total the sales. I then joined the two in QMailed vs Sold.

    In Qmailed vs Sold, I have summarized on the Make not the Model. Accura, BMW, Cadillac, etc.

  26. #26
    Forum Contributor
    Join Date
    11-28-2011
    Location
    St. Louis, Missouri
    MS-Off Ver
    Excel 2007 & 2013
    Posts
    129

    Re: Counting between two tables

    So I should go off the QMailed vs Sold query and not the qJoinTables?

  27. #27
    Forum Contributor
    Join Date
    11-28-2011
    Location
    St. Louis, Missouri
    MS-Off Ver
    Excel 2007 & 2013
    Posts
    129

    Re: Counting between two tables

    Is qJoin Tables even used in this anymore?

  28. #28
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,888

    Re: Counting between two tables

    Do not need to use qJoin Tables. I did not remove it. Use only the QMailed vs Sold.

  29. #29
    Forum Contributor
    Join Date
    11-28-2011
    Location
    St. Louis, Missouri
    MS-Off Ver
    Excel 2007 & 2013
    Posts
    129

    Re: Counting between two tables

    Ok cool, that is what I thought, but wanted to ask before I deleted anything!

    Thank you so much for the help, it is working great!

  30. #30
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,888

    Re: Counting between two tables

    Your welcome. Glad to have been of help. If you are satisfied, then please mark your thread solved.

+ 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