Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

Calculated field using lookup() with argument in another table

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Calculated field using lookup() with argument in another table

    Hello! I have a question regarding the lookup() function for which I have been unable to find the answer.

    Let's say I have an Age field in table "A", which I would like to be a calculated field using the Date_of_birth field in table "B". The calculated field expression would have this form:

    Code:
    age(lookup("B", [filterstring], "Date_of_birth"),transaction_date)
    Let's say I want to use the Date_of_birth in the record in table B where Full_name_A in table A is identical with Full_name_B in table B. In such a situation, what is the correct syntax for [filterstring] please? I feel sure it must be extremely simple, yet nothing I try seems to work.

    Then again, I might be extremely simple!
    Jim

    #2
    Re: Calculated field using lookup() with argument in another table

    age(lookup("TableB", "tableA->Full_name_A=tableB->Full_name_B", "Date_of_birth"),transaction_date)

    Sometimes, you have to use a more table descriptive name, for example:
    age(lookup("TableB.dbf", "tableA->Full_name_A=tableB->Full_name_B", "Date_of_birth"),transaction_date)

    or even the full path.

    Comment


      #3
      Re: Calculated field using lookup() with argument in another table

      Jose,

      The lookup functions tend to be among the slowest in Alpha Five. To do their work they have to open the external table, find the desired record, return it, and then close the external table. Very handy, but slow.

      In general I find the indexed lookups a bit faster. To fetch a date of birth I would probably use LOOKUPD() instead of LOOKUP().

      I've attached an example I built in vers 8 for you. I expect it to work fine in vers 7.

      The CurrAge field in the SalesPeople table is defined in field rules as a calculated field. It uses LookupD() to retrieve the dob from the Contacts table based on a fullname search key. It then converts the dob to an age. It returns zero if there's no match or if the dob field is empty in the lookup table.

      Misgivings:

      Many would advise you not to name a table field using the same name as one of Alpha's built in function. Your "Age" table field bears the same name as Alpha's AGE() function. I recommend you change your table fieldname to something else.

      Many have had bitter experiences basing searches on full names. Names are not unique. Users often mistype them. People change their names. Searches fail or return the wrong records. Not a reliable approach in many cases. I would probably never base a table field rule on this kind of "match" and would look for alternatives.

      Many recommend against storing a person's age in a table. The "age" for any person in the table is only valid until their next birthday. People have different birthdays. Even if you update all the field values on January 1st each year your records will be wrong on January 2nd if someone has a birthday. All the age() function can do is compute the age at a particular time. A snapshot in time, that can be wrong the next day. As a result folks usually just compute the age when it's needed by embedding a display calc field in the form or the report. They do not store it in the table.
      Last edited by Tom Cone Jr; 12-02-2007, 08:26 AM.

      Comment


        #4
        Re: Calculated field using lookup() with argument in another table

        Hello, G! Thanks for your post.

        I tried following your example. Here's a screenshot of the actual expression I used. Except for the filter string, the lookup() arguments were supplied by the autocomplete feature.

        I also tried "Encounters->Datestamp" for the other age() argument, as well as "Patients.dbf" as the first lookup() argument, to no avail.

        What am I doing wrong?
        Jim

        Comment


          #5
          Re: Calculated field using lookup() with argument in another table

          Assuming the Encounters table is where the field rule is found, try changing
          Code:
          [CODE]"Encounters->Full_name = Patients->Full_name"
          to
          Code:
          "Full_name = Patients->Full_name"
          [/CODE]
          This won't work for the reasons Tim points out, below.


          --------------------------------------

          "Datestamp" is a character string. The Age() function is looking for a date type value. If "Datestamp" is a date type table field in the Encounters table, and if the Encounters table is where the field rule is defined try

          changing

          Code:
          "Datestamp"
          to

          Code:
          "eval("Datestamp")"


          Jose, this would be very easy to correct for you if you posted sample tables.
          Last edited by Tom Cone Jr; 12-02-2007, 09:00 AM.

          Comment


            #6
            Re: Calculated field using lookup() with argument in another table

            Originally posted by Tom Cone Jr View Post
            Assuming the Encounters table is where the field rule is found, try changing

            Code:
            "Encounters->Full_name = Patients->Full_name"
            to

            Code:
            "Full_name = Patients->Full_name"
            However since the filter is being used to filter the patients table as part of the lookup the portion on left side of the '=' would refer to the patient table so I would try
            Code:
            "Full_Name = " + quote(Encounters->Full_Name)
            Tim Kiebert
            Eagle Creek Citrus
            A complex system that does not work is invariably found to have evolved from a simpler system that worked just fine.

            Comment


              #7
              Re: Calculated field using lookup() with argument in another table

              Hello, Tom!

              Thanks for your suggestion and attached example. I'll give it a whirl.

              I appreciate very much the additional points you made. They are good reminders.

              Well, the reason I used full names because it looks better, with proper spacing, in a single type-in field, compared to showing three separate fields. So far I've been able to avoid most of the pitfalls you mentioned by using a lookup table of full names. For the lookup table itself, the full name is calculated from the sum of the last, first, and middle names. So the user never enters the full name as such.

              With regard to the age, I was calculating it as it was on the date of the transaction. However, you are indeed right in that, since the date of birth and the transaction date are already in the database, the age is better calculated only as needed on a form or report. I'd like to know, though, if the solution to my original question about calculated table fields will also work on a calculated layout field, that is, to compute the age from a date that's in a table other than the one to which the layout is based.

              I really appreciate the pointers and the insights I'm picking up from this board.

              Thanks again!
              Jim

              Comment


                #8
                Re: Calculated field using lookup() with argument in another table

                Good catch, Tim. You're right. Thanks. -- tom

                Comment

                Working...
                X