Results 1 to 7 of 7
  1. #1
    Sam is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Nov 2022
    Posts
    50

    Help with Calculated Field

    I have a Billing table with the following fields - BillID(PK), BookingID(FK), BillNo(text), BillPercent(Number) and BillDetails(text).

    I need to put in a calculated field after BillPercent, which will give me a sum of the previous BillPercents for the BookingID.

    What should the expression be like ?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    What do you mean by sum? BookingID will have multiple records? How is BillPercent derived?

    It is usually a bad idea to save calculated data, especially aggregate calc. Calculate when needed.

    Looks to me like should probably build a report and do aggregate calculations there. Maybe even use textbox RunningSum property.
    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
    Sam is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Nov 2022
    Posts
    50
    Click image for larger version. 

Name:	Screenshot 2023-01-06 091932.jpg 
Views:	17 
Size:	50.9 KB 
ID:	49437

    To clarify I have attached an image of a sample.
    Let's say I now want to add a new record, which would be BillID 5, for BookingID 1, I need the calculated field to sum the previous entries in BillPercent (1 and 3) for BookingID 1

    I hope I am clear. In layman language I want the previously billed percentage for this person.
    Your suggestion of the RunningSum sounds right. How do I go about doing that ?

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Build a report. Textbox RunningSum property is only available on report. Use report Sorting & Grouping features as well.

    You would enter record and commit to table then run report.

    Calculating a sum for selective records on form is possible with DSum() function in form header or footer section.

    =DSum("BillPercent","Billing","BookingID=" & [BookingID])

    However, if filter is applied to form, this calculation might not return correct result. Also, it will not reflect new record entered until record is committed to table.
    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
    Sam is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Nov 2022
    Posts
    50
    Quote Originally Posted by June7 View Post

    =DSum("BillPercent","Billing","BookingID=" & [BookingID])
    I used this in a query and it works fine giving me the sum of BillPercent for that BookingID. But I still need to set the additional criteria to sum all BillPercent in the previous records up to current record.

    In other words I need to Sum all BillPercent for a particular BookingID where BillID is less than current BillID.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    That still sounds like a running sum calculation. Methods to accomplish:

    1. nested subquery

    2. VBA custom function

    3. DSum("BillPercent", "Billing", "BookingID = " & [BookingID] & " AND ID<=" & [ID])
    Or use BillDate instead of ID in the criteria: " AND BillDate<=#" & [BillDate] & "#"
    Since your data shows international date format, suggest you review http://allenbrowne.com/ser-36.html

    4. report with textbox RunningSum property


    Review https://www.tek-tips.com/viewthread.cfm?qid=1532770
    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
    Sam is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Nov 2022
    Posts
    50
    Thanks a ton June. Got it working.

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

Similar Threads

  1. Replies: 4
    Last Post: 02-09-2019, 05:38 PM
  2. Replies: 1
    Last Post: 12-10-2017, 01:47 AM
  3. Replies: 1
    Last Post: 05-22-2017, 05:59 AM
  4. Replies: 3
    Last Post: 04-09-2017, 08:01 PM
  5. Replies: 2
    Last Post: 12-30-2014, 01:32 PM

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