Results 1 to 7 of 7
  1. #1
    warhead92100 is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Aug 2015
    Posts
    19

    Dynacmic DLOOKUP in Query

    Hi All,

    I have this 2 table:

    Table1:
    SITE 12AM 1AM 2AM 3AM
    A 1500 1490 1300 1500
    B 600 800 740 900
    C 600 600 600 600
    A 9000 150 30000 5
    B 6 8 67 8

    and

    Table 2
    TIME A B/C
    12 AM
    1 AM
    2 AM
    3 AM




    Basically I would like to create a query that will lookup the values (by specific time) for all A in Table1 and sum up the B and C.

    Can anyone guide me how to do this?

    Thanks!

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    Really don't understand "lookup the values (by specific time) for all A in Table1 and sum up the B and C". Data structure makes no sense. How is record A related to records B and C? The records are always sets of 3? How should Access know which A goes with which B and C? Exactly what is the criteria for the DLookup? How does 'lookup for all A' get the data from B and C for summing?
    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
    warhead92100 is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Aug 2015
    Posts
    19
    Table 1 variables are "Site", "12AM", "1AM", etc. Table 2 variables are "Time", "Site A", "Site B", etc etc.

    I need to get the values of Site A - 12 AM from table 1 to be the value of 12AM - Site A in Table 2.

    from table above:

    Table 2, Row 1 should be:

    TIME | A | B/C
    12AM | 10500 | 1206

    ** | - used to depict different columns
    *** Sites in table 1 are dynamic, but not in table 2
    **** Time in table 2 are already keyed in, the query will append this table with the data from Table 1

    any idea?

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    A UNION query:

    SELECT "12AM" AS MyTime, Sum(IIf([Site]="A",[12AM],0)) AS [A], SUM(IIf([Site]="B" Or [Site]="C",[12AM],0)) AS [B_C] FROM table1
    UN ION SELECT "1AM", Sum(IIf([Site]="A",[1AM],0)), SUM(IIf([Site]="B" Or [Site]="C",[1AM],0)) FROM table1
    ... ;

    There is no query builder or wizard for UNION, must type in SQL View. There is a limit of 50 SELECT statements.

    Or build the UNION with raw data (no aggregate calcs) which essentially produces the normalized structure data should have been in first place. Then use the UNION in subsequent queries to do calcs or as report RecordSource.

    SELECT Site, "12AM" AS MyTime, [12AM] AS Data FROM table1
    UN ION SELECT Site, "1AM", [1AM] FROM table1
    ... ;

    So there really is no need for Table2 unless the goal is to normalize the data structure and this manipulation is a one-time event.
    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
    warhead92100 is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Aug 2015
    Posts
    19
    Quote Originally Posted by June7 View Post
    A UNION query:

    SELECT "12AM" AS MyTime, Sum(IIf([Site]="A",[12AM],0)) AS [A], SUM(IIf([Site]="B" Or [Site]="C",[12AM],0)) AS [B_C] FROM table1
    UN ION SELECT "1AM", Sum(IIf([Site]="A",[1AM],0)), SUM(IIf([Site]="B" Or [Site]="C",[1AM],0)) FROM table1
    ... ;

    There is no query builder or wizard for UNION, must type in SQL View. There is a limit of 50 SELECT statements.

    Or build the UNION with raw data (no aggregate calcs) which essentially produces the normalized structure data should have been in first place. Then use the UNION in subsequent queries to do calcs or as report RecordSource.

    SELECT Site, "12AM" AS MyTime, [12AM] AS Data FROM table1
    UN ION SELECT Site, "1AM", [1AM] FROM table1
    ... ;

    So there really is no need for Table2 unless the goal is to normalize the data structure and this manipulation is a one-time event.
    I understand less than half of the notes above.

    I'm not really familiar with SQL. Do you know a quick and easily digested guide for it?

    Thanks!

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    Here is a good start http://www.w3schools.com/sql/sql_union.asp

    Try building the second query I suggested then use that query object just like a table in subsequent queries or as report RecordSource.
    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.

  7. #7
    warhead92100 is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Aug 2015
    Posts
    19
    reps added.

    very helpful, though I just barely understand it.

    Thanks again June.

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

Similar Threads

  1. dlookup on query
    By molly13 in forum Access
    Replies: 3
    Last Post: 10-21-2014, 09:00 AM
  2. Need help on Dlookup within query
    By cp1981 in forum Queries
    Replies: 9
    Last Post: 07-25-2014, 01:57 AM
  3. Dlookup in query
    By Bertrand82 in forum Queries
    Replies: 9
    Last Post: 11-14-2012, 06:42 AM
  4. DLookup in Query
    By mfrey40 in forum Queries
    Replies: 3
    Last Post: 12-27-2011, 12:41 AM
  5. Query with Dlookup
    By mari_hitz in forum Queries
    Replies: 5
    Last Post: 10-14-2011, 09:22 PM

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