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

why tablesum() cannot summarize data correctly

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

  • why tablesum() cannot summarize data correctly

    Hi all

    I have a single table Act_rec_paid.dbf and has the structure below

    member_id name paid_date amount_paid totalsum
    001 peter 11/03/2010 600
    002 john 11/03/2010 800
    007 david 12/03/2010 1000
    002 john 13/03/2010 400
    002 john 14/03/2010 900 1200

    I set the calculate field rule for totalsum with expression below

    TABLESUM("act_rec_paid.dbf", "Member_Id = " + QUOTE(MEMBER_ID) , "Amount_Paid")

    I want to summarize all amount_paid of each user id on form (created from all field of this table)

    I expect the calculate field Totalsum in form show all amount paid of john (member_id = 002) = 800+400+900 = 2100
    but when I use the above expression it shows the tablesum() only 1200
    it missed to sum the last record (900).
    it sum 800+400 and show 1200 only

    How can I let it sum the data to the last record.
    or calculate the totalsum() has the result = 800+400+900 and show 2100
    in the Totalsum field.

    Thanks
    Peter-th

  • #2
    Re: why tablesum() cannot summarize data correctly

    Peter-th,

    The Tablesum() function runs against records that have been saved to the table. Are you expecting it to include all the previous records AND the new record you are just entering but have not yet saved?

    What do you see if you re-evaluate field rules for your table?

    -- tom

    Comment


    • #3
      Re: why tablesum() cannot summarize data correctly

      Hi Tom,

      Yes, I'm expectin it to included all previous records AND the new record that just entering but not yet saved

      member_id name paid_date amount_paid totalsum
      001 peter 11/03/2010 600
      002 john 11/03/2010 800
      007 david 12/03/2010 1000
      002 john 13/03/2010 400
      002 john 14/03/2010 900 1200

      the last record I just enterring and what it to show in the same form (just entering)
      I want the totalsum record show value = 800+400+900 = 2100
      or if no choice I can save and then it can show the 2100 in Totalsum later is ok.

      how can I let the tablesum() to calculate all record for john.

      What I have to do or try for this

      Thanks
      Peter-th

      Comment


      • #4
        Re: why tablesum() cannot summarize data correctly

        Yes, I'm expectin it to included all previous records AND the new record that just entering but not yet saved
        So now you understand why tablesum() can't do this, right? Your calc field rule must be computed BEFORE the new record is saved. When that computation occurs the record being saved has NOT YET been saved so it doesn't get counted. Is this clear?

        In most applications its not necessary to store values that can be easily computed when needed later on. Why do you need to store the "snapshot" total when a record is entered or changed? I ask because later on when the user makes other changes or enters additional records the previously stored "snapshot" total is no longer accurate and has to be recomputed all over again.

        -- tom

        Comment


        • #5
          Re: why tablesum() cannot summarize data correctly

          Hi Tom,

          I have a table and form to keep record when customer paid money for all invoice he debt last month. Usually I can use one record for each customer for each month but I need in case customer may paid twice or more for that month so I have to use tablesum() to cumpute the previous record he paid up until now he's trying to pay money. So why I want tablesum() to compute the previous record and last record (but not yet save) and show or can tell him how much total he paid .

          I also add Save button in form when I click save the totalsum() still not compute the last record I just entering the data

          Please advise the right way I should do it.

          Many thanks
          Peter-th

          Comment


          • #6
            Re: why tablesum() cannot summarize data correctly

            also add Save button in form when I click save the totalsum() still not compute the last record I just entering the data
            Ok. You are missing the point in my previous messages. Let me try one more time. Here's what the tablesum() function does. It opens a new instance of the table, runs a query based on your filter expression, and then sums the field values you specify. It then closes that instance of the table. When you use this function in a calc field rule the function is called BEFORE the current record is saved. When you press the SAVE button the calc occurs. But it occurs before the new record is saved. The result, as you've seen, is that the function cannot be used in a calc field rule to get a total that includes the new record. Is this clear?

            If I needed to see the sum of previous payments I'd put a variable on my form and I'd use a button that ran a short script. The script would use tablesum() to compute the total payments and then it would assign that total to the variable and refresh the object displaying the variable. Use the button before the new transaction to see the total of previous payments. Use the button after saving the current payment record to see the total including the new record.

            Comment


            • #7
              Re: why tablesum() cannot summarize data correctly

              Originally posted by Tom Cone Jr View Post

              to the variable and refresh the object displaying the variable.
              Hi Tom,

              Thank you for your quick response and drive me the right way
              I understand very clearly for the tablesum() process now.

              I have just put more 2 steps to compute the previous record previous payment keep it it variable and calculate with the current payment record using variable and button

              May I know what special command can refresh the object displaying the variable?

              Many Thanks
              Peter-th

              Comment


              • #8
                Re: why tablesum() cannot summarize data correctly

                Object_name.refresh()

                Comment


                • #9
                  Re: why tablesum() cannot summarize data correctly

                  Did you try re-indexing the table you are summing? Or sometimes I find that if the filter for the tablesum() function is logically comparing two character fields it will often not consider "John " equal to "John". When I compare two character fields in a tablesum() filter i use the alltrim() function...


                  Code:
                  TABLESUM("act_rec_paid.dbf", "alltrim(Member_Id) =  alltrim('"+MEMBER_ID+"')" , "Amount_Paid")
                  Lee Goldberg
                  Software Development and Sales
                  Shore Consultants Ltd.
                  [email protected]
                  www.shorecon.com

                  Comment


                  • #10
                    Re: why tablesum() cannot summarize data correctly

                    Hi Tom,

                    May I ask you more a question.

                    Where I should be placed Object_name.refresh()?
                    in button when I click and calculate or the calculate field

                    Thanks
                    Peter-th

                    Comment


                    • #11
                      Re: why tablesum() cannot summarize data correctly

                      Thank you Lee,

                      I will check and try alltrim() too

                      Comment


                      • #12
                        Re: why tablesum() cannot summarize data correctly

                        Peter, here's an example for you, using data from the AlphaSports database. Unzip the attachment to an empty folder. Compare the behavior of the calculated display field and the variable on the form, as you change the quantity for an invoice item. Watch what happens when you navigate between records. Does this help?

                        Comment


                        • #13
                          Re: why tablesum() cannot summarize data correctly

                          Tom , That is good example it helps me so much

                          Many thanks
                          Peter

                          Comment


                          • #14
                            Re: why tablesum() cannot summarize data correctly

                            Originally posted by goldberg2727 View Post

                            Code:
                            TABLESUM("act_rec_paid.dbf", "alltrim([COLOR="DarkRed"]Member_Id[/COLOR]) =  alltrim('"+[COLOR="darkred"]MEMBER_ID[/COLOR]+"')" , "Amount_Paid")

                            May I ask you I sometime confuse when I use tablesum

                            What is difference between Member_Id and MEMBER_ID (in red)
                            Member_Id is a field in act_rec_paid.dbf ,right? how about the MEMBER_ID ?


                            when I test
                            tablesum("act_rec_paid.dbf" , "Member_Id = '001' " , "Amount_Paid")
                            It works if I specific the member_id

                            but why it doesn't work when I select the Member_Id from the simple list (to change the member_id to value what I want to calculate)

                            What I have to use expression if I want to summarize for each Member_Id (select from list)

                            tablesum("act_rec_paid.dbf", "Member_Id = ????? , "Amount_Paid")

                            Thanks
                            Peter-th

                            Comment


                            • #15
                              Re: why tablesum() cannot summarize data correctly

                              Originally posted by peterth View Post
                              What is difference between Member_Id and MEMBER_ID (in red)
                              The 2nd use is the current record's value, whereas the 1st is the field to get when reading all the records. So if the current record's member ID is "12345" then
                              "alltrim(Member_Id) = alltrim('"+MEMBER_ID+"')"
                              is evaluated to a string
                              "alltrim(Member_Id) = alltrim('12345')"
                              which is the filter expression that TABLESUM() uses to decide what the records are to sum.
                              Regards,

                              Ira J. Perlow
                              Computer Systems Design


                              CSDA A5 Products
                              New - Free CSDA DiagInfo - v1.39, 30 Apr 2013
                              CSDA Barcode Functions

                              CSDA Code Utility
                              CSDA Screen Capture


                              Comment

                              Working...
                              X