Results 1 to 5 of 5
  1. #1
    scottc_00 is offline Novice
    Windows XP Access 2007
    Join Date
    Jan 2015
    Posts
    5

    Create new field from 1 of 3 fields based on value.

    I have a data table that contains data that was created by someone else. I only take that data and drop it in my table so I can work with it. I realize that the data setup is nonsense. I am just trying to work with what I have.
    The table contains 10 fields. 3 of those fields contain values that I want to put in a new field IF the value meets certain criteria. I will call the fields Lvl6, Lvl7, Lvl8, and the new field will be Lvl678.

    If the value of Lvl6 = Beatles then Lvl678 = Beatles
    If the value of Lvl7 = Kinks then Lvl678 = Kinks
    If the value of Lvl7 = Stones then Lvl678 = Stones
    If the value of Lvl8 = Doors then Lvl678 = Doors
    Etc



    I tried to set up a new “rollup” table like this
    Lvl6 Lvl7 Lvl8 Lvl678
    Beatles Beatles
    Kinks Kinks
    Stones Stones
    Doors Doors

    And then I created a query to join the data table with this “rollup” table on Lvl6, Lvl7, Lvl8 so that the resulting data would include the field Lvl678.

    I adjusted the Join Properties for ALL rows from the data table and ONLY the rows from the “rollup” table where the joined fields are equal.

    So I am getting the data but the field Lvl678 is blank. I tried different join properties with no luck. FYI…I am fairly new to Access. I have been using it for years to store data and pull it out using Excel pivot table setc but I am no expert when it comes to Queries etc.

    Thanks for your help.

  2. #2
    scottc_00 is offline Novice
    Windows XP Access 2007
    Join Date
    Jan 2015
    Posts
    5
    I have figured out that I can use the switch function and that works fine. But it would be nice if this table comparison would work. Anyone have any ideas ?

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    Not really understanding why you have the 'rollup' table anyway. A query can generate the Lvl678 field and retrieve all the data from the original table.
    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.

  4. #4
    scottc_00 is offline Novice
    Windows XP Access 2007
    Join Date
    Jan 2015
    Posts
    5
    The only way I know to do that is by using the switch function. That works but it seems like a lot of hard keyed criteria in an experession. If I ever need to build another query similarly I will have to do the same thing again. I think if I had the rollup table I could just use that same information in all my queries that need that rollup. Also if anything changes I would only have to change it in one place if I use a rollup table. If I use a switch function in all of my queries I will have to change it in each individual query.

    It is highly likely that I am missing something obvious to someone with more experience. Any advise would be greatly appreciated.
    Thanks

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    A query can be used in other queries, like a table.

    I do not understand why you want the calculation anyway. I do suspect data structure is not normalized.

    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: 1
    Last Post: 04-21-2014, 02:28 PM
  2. Replies: 3
    Last Post: 08-28-2013, 11:08 PM
  3. Replies: 10
    Last Post: 07-19-2013, 02:05 PM
  4. Create tables based on field value
    By fpmsi in forum Programming
    Replies: 5
    Last Post: 11-17-2011, 12:42 PM
  5. Replies: 3
    Last Post: 02-17-2010, 02:29 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