Results 1 to 6 of 6
  1. #1
    kestefon is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2013
    Posts
    108

    Query To Add Empty Records To Dataset?

    Hi,


    I have a dataset showing sales by salesperson for each product. I'd like to summarize this data in a table that looks like this:




    Click image for larger version. 

Name:	DesiredResult.png 
Views:	8 
Size:	36.9 KB 
ID:	17601

    Note that some salespeople don't sell certain products and that these records show up with "0". My problem is that, in my actual dataset, if a salesperson doesn't sell a product, that records doesn't exist at all. Is there any way to append empty "0" records to my dataset? See attached for an Access file.


    DatasetProblem.accdb

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    This will require a dataset of every possible salesperson/product combination. That dataset can be generated with query that includes those two tables WITHOUT a join. This results in a Cartesian relationship - every record in each table will join with every record in other table.

    SELECT SalespersonID, ProductID FROM SalesPersons, Products;

    Do the crosstab query.

    Join the crosstab query to the Cartesian query, compound link on the SalespersonID and ProductID fields, join type "Include all records from {Cartesian query name}..."
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    kestefon is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2013
    Posts
    108
    Awesome, thanks! One question...I tried joining the crosstab to the cartesian query with a left join, and it's resulting in duplicate records from the dataset. Any idea how I can get rid of those?

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Did you do compound join?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    kestefon is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2013
    Posts
    108
    What would that look like? I wrote it into the WHERE clause, i.e. "WHERE a.Field1&a.Field2 = b.Field1&b.Field2"

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    I suppose that should work. But a compound join will show multiple linking lines between the tables in the query builder.

    If you want to provide db for analysis, follow instructions at bottom of my post.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 6
    Last Post: 02-18-2014, 08:36 AM
  2. Replies: 1
    Last Post: 08-29-2013, 11:38 AM
  3. Replies: 4
    Last Post: 07-28-2011, 06:57 AM
  4. saving records without null or empty fields
    By amber mara in forum Access
    Replies: 1
    Last Post: 05-05-2010, 02:34 PM
  5. Hiding fields that contains empty records
    By sakthivels in forum Reports
    Replies: 4
    Last Post: 05-27-2009, 07:06 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums