Results 1 to 7 of 7
  1. #1
    hugoj is offline Novice
    Windows 8 Access 2010 32bit
    Join Date
    Nov 2014
    Location
    Sweden
    Posts
    6

    How to select percentage of records based on their values

    Hi

    I have as a start made a Query with the following field: Running total: DSum("Ordersumma";"Order";"[Ordersumma]<=" & [Order sum])

    That line produces the total sum at the first record and then continues down to zero.


    The result is fine but in the end I want to select e.g. the order values that make up 80% of the total value. So how do I continue to select only those records.

    In the query's property sheet I can select 10% of the total records but that is not valid in this case since I want to base the percentage upon the values.

    Best regards

    Hugo

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,598
    So the cutoff would be where the DSum >= 20% of the total? The total is [Order sum]?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    hugoj is offline Novice
    Windows 8 Access 2010 32bit
    Join Date
    Nov 2014
    Location
    Sweden
    Posts
    6
    The cutoff is where the DSum >=20% but the total is the Running total. "Ordersumma" is the field in the table. [Order sum] is a renamed field which is the "copy" of "Ordersumma". So this field I use for comparison against the field in the table.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,598
    Need to know the grand total to calculate the % target.

    Don't know why you would need to copy Ordersumma field.

    If you want to provide raw data for analaysis, attach file (Access or Excel). Follow instructions at bottom of my post.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    hugoj is offline Novice
    Windows 8 Access 2010 32bit
    Join Date
    Nov 2014
    Location
    Sweden
    Posts
    6

    Dummy Data provided

    I have attached one table with orders and the query I use. I searched online how to use the DSum function with this purpose.
    And according to Microsoft online help I should use it like that. I tried to skip the field I created and compare Ordersumma to Ordersumma but Access complained when I did that. So this function works fine when showing the values. But dont reach my ultimate goal of showing only the orders that make up 80% of the total.

    Hugo
    Attached Files Attached Files

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,598
    Consider:

    SELECT Order_2.Ordersumma AS Ordervärde, Sum(Order_2.Ordersumma) AS SumOfOrdersumma, DSum("Ordersumma","Order_2","[Ordersumma]<=" & [Ordervärde]) AS [Running total], qryEnbart_total.Total, DSum("Ordersumma","Order_2","[Ordersumma]<=" & [Ordervärde])/[Total]*100 AS Pct
    FROM Order_2, (SELECT Sum(Ordersumma) AS Total FROM Order_2) AS qryEnbart_total
    GROUP BY Order_2.Ordersumma, qryEnbart_total.Total
    ORDER BY Order_2.Ordersumma DESC;

    Can delete the qryEnbart_total object because the SQL is nested into the above.

    However, when I apply filter criteria to the Pct field I get an input popup.

    So build another query that uses the above as source.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    hugoj is offline Novice
    Windows 8 Access 2010 32bit
    Join Date
    Nov 2014
    Location
    Sweden
    Posts
    6
    Thanks! Works perfect!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 6
    Last Post: 02-23-2014, 03:54 PM
  2. Replies: 12
    Last Post: 10-10-2013, 11:51 AM
  3. Select record based on values of other records
    By dchaboya in forum Queries
    Replies: 2
    Last Post: 08-11-2011, 10:41 AM
  4. Replies: 1
    Last Post: 07-11-2011, 05:12 AM
  5. Replies: 3
    Last Post: 01-04-2011, 07:06 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums