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

Need help with First() function

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

    Need help with First() function

    I have police officers filling out a daily activity log, which starts off with the patrol vehicle's starting and ending mileage reading. (The total miles are caculated.) Sometimes they use the patrol vehicle on their days off for non-patrol activities, such as going to court, and on those days they do not record their mileage.

    Each month I produce a "Monthly Activity Report,", and two of the fields are "Starting Mileage" and "Ending Mileage." Normally I would get the information from the first starting mileage entered for the month by using the first(startingmileage) expression, and last(endingmileage) for the last day of the month, but I'm running into problems where the officer used the vehicle on the first or last day of the month, and for whatever reason, does not have a starting or ending mileage listed.

    In those cases I'm (naturally) getting a resulting Starting (or Ending) Mileage of "0".

    So my question is, how can I write the expression to assure me that I am getting the first mileage of the month that is NOT "0", and the last mileage of the month that is NOT "0." (or >0 or something like that) ?
    Sergeant Richard Hartnett
    Hyattsville City Police Department
    Maryland

    #2
    Re: Need help with First() function

    Report writer functions such as first() are not filterable. Since you can't really have a "Starting Mileage" field, let's call it startm.

    You might be able to create a calculated field

    realfirst = if(statrm >0,startm,9999999999999)

    Then create another calculated field like your current first() but use minimum().
    There can be only one.

    Comment


      #3
      Re: Need help with First() function

      sounds like you need:
      dbmin() and dbmax() ... where the filter in each will contain the month in question and startingmilge <>0

      Comment


        #4
        Re: Need help with First() function

        Stan thanks for the reply, but I really don't understand the answer. (I'm sure it's just me.)

        My actual field is called "StartingMileage." If I create a calculated field based on your formula, it looks like this:

        StartingMileage = if(startm >0,startm,9999999999999)

        but the resulting answer is logical. (T/F)

        So am I now creating a minimum(startingmileage) calculated field based on the first true "startm" entry?

        And if so, how?
        -----------------------------------------------------------------------

        And Gabe, I tried to use dbmin(), but was confused on the parameters.
        My table name is: "admin_ncpd"
        The only options I have for c_tagname are: Date & Record_No
        For key value, I assume it would be <>0 (or maybe >0)
        But for the "c_field" name, of course it is looking for a character field, and my StartMileage field is numeric.

        Can you explain how to propertly set up the dbmin() function with these parameters?
        Sergeant Richard Hartnett
        Hyattsville City Police Department
        Maryland

        Comment


          #5
          Re: Need help with First() function

          I think your best bet is a UDF given the fact that dbmin() and dbmax() require an index and given the fact that you are searching within a certain date, i.e. the index has to be updated before running the calculation, you might as well use a UDF.
          Here is a pseudo-code:
          Code:
          Function millage as N (search_month as n, vehicle as C)
          t=table.open(...)
          t.query_create("t","put here filter to check for search_month","put here order by millage")
          t.fetch_first()
          if t.millage=0
          t.fetch_next()
          start_mil=t.millage
          end if
          t.fetch_last()
          if t.millage=0
          t.fetch_prev()
          end_mil=t.millage
          end if
          millage=end_mil-start_mil
          End Function
          The filter would be something like:
          "month(your_date_field=var->search_month.vehicle_field=var->vehicle"

          Edit:
          posted before reading your latest post.. rather than addressing any issues with dbmin() and dbmax(), try the UDF.
          Last edited by G Gabriel; 02-16-2009, 03:36 PM.

          Comment


            #6
            Re: Need help with First() function

            I said create a new calculated field.

            realfirst = if(StartingMileage >0,StartingMileage,9999999999999)

            For any record with a starting mileage of zero, the expression returns 9999999999999. Since it is unlikely to have a vehicle with 9999999999999 miles on the odometer, when you use the minimum() on the calculated field this record will be excluded. The minimum() function should return the lowest recorded mileage > 0.
            Last edited by Stan Mathews; 02-16-2009, 02:21 PM.
            There can be only one.

            Comment


              #7
              Re: Need help with First() function

              This may be a little off the subject, but....

              you might want to limit all field and variable names to 10 characters or less.

              If A5 crashes, and you have more than one field name that starts with the
              same 10 characters, they will all be truncated to the first 10 characters.

              That means you will have multiple fields with the same name. Every place that
              you use that field name (scripts, functions, etc) will cause errors. And some
              will not be evident until bad data starts showing up.

              Doesn't happen very often, but once will be more than enuff. Everyone seems
              to go thru the long, explicit field/variable name phase, cuz it's easy to read.

              D

              Comment


                #8
                Re: Need help with First() function

                Thanks Stan. I actually WAS creating a new calculated field, but not correctly. After reading your last post it made sense to me, and it works just as you described.

                Thanks again.

                _______________________________________________

                And dik_coleman I hear you loud and clear!

                I should have known better than to have long field names. I actually did have a database crash several years ago, and I did experience the problem with truncated field names. What a pain that was.

                I'll have to be more creative with my field names in the future.

                Thanks everyone.
                Sergeant Richard Hartnett
                Hyattsville City Police Department
                Maryland

                Comment


                  #9
                  Re: Need help with First() function

                  There is of course the possibility that the minimum recorded mileage is also an error like the non recorded mileage of 0. The minimum function does not look for the first recorded mileage > 0, just the lowest recorded mileage. If a user was to record 1 as the mileage, that's what you'll get.
                  There can be only one.

                  Comment


                    #10
                    Re: Need help with First() function

                    Not really sure why are you concerning yourself with the starting millage of the month? Isn't the same as the ending millage of the previous month? and the ending millage is simply maximum() for that month?
                    Last edited by G Gabriel; 02-16-2009, 04:48 PM.

                    Comment


                      #11
                      Re: Need help with First() function

                      Well Gabe you are right in theory, but there are times when an officer will have to change cars for one reason or another, and as a result, the starting mileage for one month, may not necessarily be the same as the ending mileage of the previous month, due to the officer driving a different patrol car.

                      If it wasn't for that though, you're right, I could have just used the previous month's ending mileage.
                      Sergeant Richard Hartnett
                      Hyattsville City Police Department
                      Maryland

                      Comment


                        #12
                        Re: Need help with First() function

                        Not to beat a dead horse, but I don't see why you can't?
                        And what happens if they change cars in the middle of the month? or a car breaks down?

                        Comment

                        Working...
                        X