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

Median value

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

    Median value

    In a population of SAT scores, how does one go about determining the median value? Simple table structure, no links, field containing Verbal, Math and Percentiles. One column for each.

    Thankyou

    #2
    Re: Median value

    Hi Jon,

    Welcome to Alpha.

    You will need a UDF for this. I cant see one built in.
    Ten people are riding on a bus in Redmond, Washington. The mean (average) income of those riders is $50,000 a year. The median income of those riders is also $50,000 a year.

    Joe Blow gets off the bus. Bill Gates gets on.

    The median income of those riders remains $50,000 a year. But the mean income is now somewhere in the neighborhood of $50 million or so. A source now could say that the average income of those bus riders is 50 million bucks. But those other nine riders didn't become millionaires just because Bill Gates got on their bus. A reporter who writes that the "average rider" on that bus earns $50,000 a year, using the median, provides a far more accurate picture of those bus riders' place in the economy.
    Check out http://msgboard.alphasoftware.com/al...ad.php?t=32736
    Last edited by Keith Hubert; 10-14-2008, 02:24 PM. Reason: added link after doing search
    Regards
    Keith Hubert
    Alpha Guild Member
    London.
    KHDB Management Systems
    Skype = keith.hubert


    For your day-to-day Needs, you Need an Alpha Database!

    Comment


      #3
      Re: Median value

      Thank you for the reply, I agree, no built ins! A thought provoking riddle!

      Jon

      Comment


        #4
        Re: Median value

        Here's a "target" folks can shoot at.

        Brute force approach to finding median:
        1) sort the records from lowest to highest
        2) determine how many records are in the list
        3) if the record count is odd, determine position of median value by dividing record count by 2, and then adding one; then fetch from lowest to highest stopping when you get to the position of the median value. This is the median value when the record count is odd.
        4) if the record count is even, determine position of the last value that's lower than the median by dividing the record count by 2; determine position of the first value that's higher than the median by dividing the record count by 2 and adding 1; fetch through the records from lowest to highest, retrieving the last value that's lower than the median and the first value that's higher than the median. Then average those two values to get the mid-point between them. This is the median when the record count is even.

        How'd I do?
        Last edited by Tom Cone Jr; 10-14-2008, 02:58 PM.

        Comment


          #5
          Re: Median value

          Excellent and extremely clear definition, however, how do I write this as an Alpha expression?

          Thanks,

          Jon

          Comment


            #6
            Re: Median value

            Jon, can't be done in an expression.

            You're going to have to write a script using xbasic. As others have recommended this could be saved in your database as a User Defined Function (UDF).

            If you post some dummy data here I daresay that someone will write it for you.

            -- tom

            Comment


              #7
              Re: Median value

              Good advice, I will attempt do so and if I don't have any luck, I will post some data, thank you.

              Jon

              Comment


                #8
                Re: Median value

                Jon,

                I think this will work (I have only tested it on a few records, but I think the logic is right):

                Code:
                FUNCTION Median as N (vcTableName as C, vcField as C, vcIndex as C)
                
                	'Calculates median value for specified table, field and index
                	'� R A Rutherford 2008
                
                	'Declare & initialise variables
                	OPTION strict
                	DIM vnErr as N							'Error number for error handling routines
                	DIM vcErrMsg as C						'Error message for error handling routines
                	DIM vnResp as N							'User response to message box
                	DIM t as P								'Pointer to selected table
                	DIM vnRecCount as N						'Number of records
                	DIM vnRecPos1 as N						'Position of 1st median record in index order
                	DIM vnRecPos2 as N						'Position of 2nd median record in index order
                	DIM vlSingleRecord as L					'Odd number of records? (therefore don't need to average values for two records)
                	DIM vnValue1 as N						'Value of 1st median record in index order						
                	DIM vnValue2 as N						'Value of 2nd median record in index order		
                	DIM i as N								'Counter
                
                	'Open tables
                	ON ERROR goto OpenError
                	t = table.open(a5.Get_Path() + chr(92) + vcTableName + ".dbf", FILE_RO_SHARED)
                	ON ERROR goto GeneralError
                	t.index_primary_put(vcIndex)
                
                	'Get number of records
                	vnRecCount = t.records_get()
                	vnRecPos1 = vnRecCount / 2
                	IF vnRecPos1 <> int(vnRecPos1) THEN		'Odd number of records, so only need to look at one record
                		vlSingleRecord = .T.
                		vnRecPos1 = round_up(vnRecPos1, 0)
                	ELSE
                		vlSingleRecord = .F.
                		vnRecPos1 = int(vnRecPos1)
                		vnRecPos2 = vnRecPos1 + 1
                	END IF
                
                	'Fetch through records
                	t.fetch_first()
                	FOR i = 1 to vnRecPos1 - 1
                		t.fetch_next()
                	NEXT
                	vnValue1 = eval("t." + vcField)
                	IF vlSingleRecord = .F. THEN
                		t.fetch_next()
                		vnValue2 = eval("t." + vcField)
                		Median = (vnValue1 + vnValue2) / 2
                	ELSE
                		Median = vnValue1
                	END IF
                
                	'Close table
                
                	CloseAll:
                	IF is_object(t) THEN
                		t.close()
                	END IF
                
                	EXIT FUNCTION
                
                	'***********************************************************
                	'//Error handling routines
                
                	'Errors not otherwise specified
                	GeneralError:
                	vnErr = error_code_get()
                	vcErrMsg = error_text_get(vnErr)
                	msgbox("Error", vcErrMsg, UI_STOP_SYMBOL + UI_OK)
                	Median = 0					'possibly change this to an unlikely value e.g. -999999999?
                	GOTO CloseAll
                
                	'Error opening table
                	OpenError:
                	vnResp = msgbox("Error opening table", "Cannot open the table for median calculation." + crlf() + "Another user may be using it.", UI_STOP_SYMBOL + UI_RETRY_CANCEL)
                	IF vnResp = ui_retry_selected THEN
                		RESUME 0
                	ELSE
                		Median = 0
                		GOTO CloseAll
                	END IF
                
                END FUNCTION
                Tony

                Comment


                  #9
                  Re: Median value

                  Thank you!

                  It works fine, how can I thank you enough? Many thanks to all the others who took a shot at it.

                  Jon

                  Comment

                  Working...
                  X