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

YTD report calculation

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

    YTD report calculation

    I have a report that tracks quotes by month and by account manager. Grouping level is 'Month' and then 'Manager'. There is no detail shown. The 'Manager' footer lists each account manager with a total amount quoted. The 'Month' footer shows the total quoted for the month. A report footer shows the total quoted for the year.

    I'd like to add a YTD field next to the monthly total shown for each account manager. I've tried several variations of the run_total function, all of them unsuccessful. Any suggestions?

    #2
    Re: YTD report calculation

    You've tried several variations of the run_total function but we have no clue what they were. A sample database would go a long way towards getting concrete help rather than guesses.
    There can be only one.

    Comment


      #3
      Re: YTD report calculation

      Stan,

      I'm not sure how to include a sample database. Here are the calculated fields I've been using so far:

      Month = cmonth(Quote_Date)
      Month_Total = total(Hrs_Quoted,Grp->Manager)
      Month_Grand = total(calc->Month_Total,Grp->Month)
      Year_Total = total(calc->Month_Grand)
      YTD_Manager = run_total(calc->Month_Total,GRP->Grand)
      YTD_Total = run_total(calc->Month_Grand,GRP->Grand)

      The last 2 fields are the ones that are giving me the trouble.

      Comment


        #4
        Re: YTD report calculation

        View the control panel.
        Use the Tools menu
        Choose Zip database
        Attach the result here
        There can be only one.

        Comment


          #5
          Re: YTD report calculation

          I'll give it a try - hopefully this works...

          Comment


            #6
            Re: YTD report calculation

            OK. The problem is

            RUN_TOTAL() is used in the Detail section of a report to return the running total
            You are trying to use it in group footers.

            I'll see if I can think of another solution.
            There can be only one.

            Comment


              #7
              Re: YTD report calculation

              Here you go.

              Comment


                #8
                Re: YTD report calculation

                The YTD results appear to be the same now in each month, based on the current YTD totals for each manager...


                I'm not sure why it works, but you might have noticed a strange calculation I tried for the overall monthly YTD total. Without adding "calc->Month_Grand" part to the run_total, the initial month's YTD calculates to 0.

                Comment


                  #9
                  Re: YTD report calculation

                  Like my screenshot?

                  I added a field run_hrs and populated it via a script that needs to be run before the report is printed to update new records.
                  There can be only one.

                  Comment


                    #10
                    Re: YTD report calculation

                    This is great! I don't pretend to understand the code, but the report works nicely. When you say the script needs to be run before the report, do you mean I should manually click on the code icon before running the report?

                    Since this is new to me, can you tell me the best way to add your changes to my working database without overwriting existing data? Do I only need to add certain files from the zip folder, or all of them? (I selected all of them and overwrote the existing files on my database copy, but I don't know if that was the right thing to do.) Even though I've worked with Alpha 5 for years, I'm a novice when it comes to more complex procedures...

                    Thanks for your help!

                    Comment


                      #11
                      Re: YTD report calculation

                      the script needs to be run before the report
                      The script can be run as often as you like. If you run the report from a button, merely add an action to run the script before the report print action. The script process all the records in the table, one manager at a time, in quote_date order to populate the run_hrs field. As you enter new records the run_hrs field is blank until the script is run.


                      best way to add your changes to my working database
                      Open your live database and add the run_hrs field to the quotes table. I defined it as numeric, 7, 0. If you think there will be more than 9,999,999 hrs_quoted for a manager, increase the 7 to something else. I inserted it in a particular position but it is not necessary. Close your live database and open the example. Go to the code tab of the control panel, hilight the pop script, right click and choose Copy To.

                      Alternatively you can export the pop script, open your database, and import it. Alternatively you can cut and paste from here to your database after beginning a new xbasic script on your code tab.

                      Code:
                      managers = table.external_record_content_get("quotes","alltrim(manager)","manager",".t. .and. unique_key_value()")
                      mgrs = w_count(managers)
                      for i = 1 to mgrs
                      	tbl = table.open("quotes",FILE_RW_EXCLUSIVE)
                      	query.filter = "manager = "+quote(word(managers,i,crlf()))
                      	query.options = "I"
                      	query.order = "cdate(quote_date)"
                      	query.description = "Temporary Query"
                      	ix = tbl.query_create()
                      	tbl.fetch_first()
                      	hrs = 0
                      	while .not. tbl.fetch_eof()
                      		tbl.change_begin()
                      		tbl.Run_hrs = tbl.Hrs_quoted + hrs
                      		tbl.change_end(.t.)
                      		hrs = tbl.Run_hrs
                      		yr = year(tbl.Quote_date)
                      		tbl.fetch_next()
                      		if yr <> year(tbl.Quote_date)
                      			hrs = 0
                      		end if
                      	end while
                      	tbl.query_detach_all()
                      	tbl.close()
                      next i
                      Nice to have lots of options.
                      There can be only one.

                      Comment


                        #12
                        Re: YTD report calculation

                        Thanks again for your help. The report works great now.

                        I copied and edited this script for another table, workordr.dbf, where I have a similar report showing estimated hours from work orders. The fields that are different are "Date" and "Run_Esthrs" instead of "Quote_Date" and "Run_Hrs". The manager field is the same as in the quotes table. For some reason, the YTD calculation works for only 2 of the 3 managers, which seems odd. I've run the script several times with the same result and can't figure out why it won't work for one manager. I can see that the "Run_Esthrs" field is populated for only 2 of 3 managers, so it doesn't appear to be a problem with the report.

                        Here is what the edited script looks like:


                        managers = table.external_record_content_get("workordr","alltrim(manager)","manager",".t. .and. unique_key_value()")
                        mgrs = w_count(managers)
                        for i = 1 to mgrs
                        tbl = table.open("workordr",FILE_RW_EXCLUSIVE)
                        query.filter = "manager = "+quote(word(managers,i,crlf()))
                        query.options = "I"
                        query.order = "cdate(date)"
                        query.description = "Temporary Query"
                        ix = tbl.query_create()
                        tbl.fetch_first()
                        hrs = 0
                        while .not. tbl.fetch_eof()
                        tbl.change_begin()
                        tbl.Run_Esthrs = tbl.Esthrs + hrs
                        tbl.change_end(.t.)
                        hrs = tbl.Run_Esthrs
                        yr = year(tbl.Date)
                        tbl.fetch_next()
                        if yr <> year(tbl.Date)
                        hrs = 0
                        end if
                        end while
                        tbl.query_detach_all()
                        tbl.close()
                        next i

                        Comment


                          #13
                          Re: YTD report calculation

                          In the interactive editor, paste in this line

                          Code:
                          ? table.external_record_content_get("workordr","alltrim(manager)","manager",".t. .and. unique_key_value()")
                          You should see a list of the manager names found in the workordr table.
                          There can be only one.

                          Comment


                            #14
                            Re: YTD report calculation

                            This worked properly - it identified each of the 3 managers. However, when I review the new Run_Esthrs field in the table, only 2 managers show data after running the script.

                            Comment


                              #15
                              Re: YTD report calculation

                              Stan,

                              I figured out the problem. I initially needed to create a "manager" field in my work order table and populate it from another field. I only populated the field for work orders after 1/1/09. When I repopulated the field for all records, the script worked and populated the Run_Esthrs field for all managers.

                              I have over 25,000 work order records, so the script takes a couple minutes to run. Is there a line I can insert to filter it to records dated 1/1/09 or later?

                              Thanks.

                              Comment

                              Working...
                              X