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

DBMAX function question

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

    DBMAX function question

    I'm trying to use dbmax and use a field name in the keyvalue, it keeps telling me unrecognized field name, how can I include field name as a key value in the function.

    table = clcf1_history
    index = Account
    keyvalue = the filed named Aaccnt_
    field to use for maximum = Initalmrg


    ?dbmax("clcf1_history.dbf","Account",clcf1_hostory->Aaccnt_,"Initalmrg")
    ERROR: Field is not recognized: 'clcf1_history->Aaccnt_'

    I'm trying to find the maximum value for every Account in the database ?
    is there a better way ?

    Thanks

    #2
    Re: DBMAX function question

    Where are you trying this? In the interactive editor, clcf1_history->Aaccnt_ has no meaning as the table is not open.

    Since you specify the table as the first parameter of dbmax() the

    clcf1_history-> is not necessary, but does no harm.

    If you create a calculated field for the table clcf1_history and make its expression

    dbmax("clcf1_history.dbf","Account",Aaccnt_,"Initalmrg")

    and reevaluate the field rules you should get the desired value. (Given an index "Account" on the AAccnt_ field.

    You can do something like this....

    Code:
    tbl = table.open("frito")
    ? tbl.type
    = "CHEETOS      "
    
    ? dbmax("frito","tst","cheetos","sls")
    = 520.000000
    
    ? dbmax("frito","tst",tbl.type,"sls")
    = 520.000000
    
    tbl.close()
    There can be only one.

    Comment


      #3
      Re: DBMAX function question

      Thanks Stan; I'm trying this on a report in the calculated field area, but I was working with the interactive window just to test.

      In the calculated area of the report it didn't take my expression, it deletes it everytime when I use the keyvalue as Aaccnt.


      dbmax("clcf1_history.dbf","Account",Aaccnt_,"Initalmrg")

      Comment


        #4
        Re: DBMAX function question

        Can you zip/attach a small sample of the table upon which the report is based? Zip from the control panel so the support files are included.

        Works fine here.
        There can be only one.

        Comment


          #5
          Re: DBMAX function question

          Originally posted by Anis View Post
          I'm trying to find the maximum value for every Account in the database ?
          is there a better way ?
          Based on this, I think you are trying to tell it to check every record in the clcf1_history database where the Aaccnt_ field matches a value in the Account index (this would be all records, of course) and find the highest Initalmrg value. The function doesn't work that way.

          The syntax is:
          DBMAX( Lookup_Table as C, Index_Tagname as C, Key_Value as A, Lookup_Expression as C )

          Where Key_value is a single value that would match a value in the index - not a field name in the lookup table itself. The Key_value is often the value from a table but not from the table that the lookup is in.

          I think the only way you can use DBMAX() to do this is to create a 'dummy' field that is always filled with one value then build an index on that field. HOWEVER, it's probably much easier with...

          TABLEMAX( Lookup_Table as C, Filter as C, Lookup_Expression as C )

          Probably:
          Tablemax( "clcf1_history", ".T.", "Initalmrg" )

          Comment


            #6
            Re: DBMAX function question

            Here's the database zipped.

            Thanks Cal for jumping in.

            In the A5 documentation it says the keyvalue could be a field name for DBMAX!!

            To create a dummy field, the expression you had will pick the largest amount in the table not for that specific account.
            If the database has many accounts and many dates, I want to pick up the largest "Initalmrg" for each specific account historically.

            Comment


              #7
              Re: DBMAX function question

              Works fine here.
              There can be only one.

              Comment


                #8
                Re: DBMAX function question

                OK. I misread your intent with "I'm trying to find the maximum value for every Account in the database". I read that as the max of all records.

                Re: In the A5 documentation it says the keyvalue could be a field name for DBMAX!!

                What it actually says is, "An explicit value or the name of a field in the table containing a value."

                And, yes, that's poorly worded. I think it would be better as, "An explicit value or the name of a field in an external table containing a value." The function only returns one value so which one should it return if you give it the name of a field in the lookup table itself? It can't automatically get a list of all values for that field and return a list of all maximums from another field. A function could be written to do that but this one doesn't.

                I don't have time to go into your sample in depth right now - maybe later if Stan doesn't get it first.

                EDIT: After looking at Stan's screenshots, maybe I'm wrong. As long as the layout is using the same table, I can see where it might work. I've just never thought of using it that way.

                LATER: Yep - learned a new technique today. It works. I tested it in a form and it works fine there - as it should once I thought about it. The trick is the "scope" of "a field in the table" as used in the Help file. As long as the field has a value - such as when used in a layout that is based on that table - it will work. However, using that same expression in the Interactive Window won't work unless you first open the table then run the dbmax() function. In other words, the dbmax() function can't "see itself" but if you think of the dbmax() function as opening the table in another session, you can use a field from the same table in a different session to specify the index value to be used - i.e., when working in a layout based on the same table, you can give it the name of a field in the layout even though it's from the same table used in the lookup. You are really passing a value to the function - not a field name. The value simply happens to be represented by a field name in this case.
                Last edited by CALocklin; 12-08-2009, 03:08 PM.

                Comment


                  #9
                  Re: DBMAX function question

                  Thanks Stan/Cal

                  Stan; I'm completely astonished, becuase I reviewd that entry many times and it was correct, yet it was rejected.

                  I'm trying again now

                  Comment


                    #10
                    Re: DBMAX function question

                    Thanks Stan, that just worked fine. I'm still puzzled.

                    I appreciate your time guys.

                    Comment


                      #11
                      Re: DBMAX function question

                      the dbmax() function can't "see itself" but if you think of the dbmax() function as opening the table in another session
                      Cal,

                      Just tried something this morning. Not only can the dbmax() function not see itself. The dbmax() function doesn't see an exclusive use flag.

                      Code:
                      tbl = table.open("frito",FILE_RW_EXCLUSIVE)
                      
                      ? dbmin("frito","tst","cheetos","sls")
                      = 0.000000
                      
                      ? dbsum("frito","tst",tbl.type,"sls")
                      = 1134.000000
                      
                      tbl.close()
                      There can be only one.

                      Comment


                        #12
                        Re: DBMAX function question

                        It sees.
                        Any table function is NOT restricted by opening the table in any manner else the world of xbasic will come to a halt.
                        Try dbmax(), not dbmin(). Zero is probably the correct answer for dbmin().

                        Comment

                        Working...
                        X