Results 1 to 10 of 10
  1. #1
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228

    calculating total job costs.

    every job I have in the database has additional costs as a child record. There are multiple additional costs for each job.

    Our clients want a breakdown of what these are (this is done) but also the total cost for each job.

    EG:
    Job 1 = x £300, Y £400

    the client wants to see

    Job 1 = £700

    so.. I cant get my head around what I need to do in the query to combine like this and list all the jobs and totals.



    The naming I have for any table/query doesn't matter, neither does my business plan or my relationships, before people start asking for them haha. This is a theory question so the answer should be applicable to any database.

    relations between child and parent records and how to manipulate child record costs into a total. that's all I want if someone could point me in the right direction.

    Thanks.

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    I would probably create an alias in a query that sums the additional costs. Then, add the additional costs to the original cost.

  3. #3
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    It doesn't need to be added to the original cost, they are paid no problems up front. but thanks for the tip I will research your suggestion now.

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    A totals query may provide the results you desire. You can create a totals query by clicking the Sigma symbol from within the query designer. When you add fields to your query, you can Sum a specific field by changing "Group By" to "Sum".

  5. #5
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    Yes, I actually found that whilst looking up alias querys, It will help a few different projects I have on at the moment. I have another question..

    http://prntscr.com/8yydc2 <--query
    http://prntscr.com/8yybav <-- Results

    is there a way to concatenate text strings from the child records?

    EG

    job 1 = "description 1", "description 2"

    that way they still get all the information but its in one text block with one price. My brain isn't working today and I cant figure out where to even begin.

  6. #6
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    http://allenbrowne.com/func-concat.html

    Think this is what I'm after, Ill give it a go.

  7. #7
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    That should do it. Consider the example provided by Allen where he uses CompanyID. If your query retrieves duplicate values of CompanyID, I would not call the function from the query. Instead, call the function from a control. If you are using a report and calling the function from a particular control within a Report does not work, you can use VBA in the Report's On Load and On Format events.

    From Allen's site ...
    Code:
    For the example above, you could set the ControlSource of a text box to:
         =ConcatRelated("OrderDate", "tblOrders", "CompanyID = " & [CompanyID])

  8. #8
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    Okay thanks mate, I do have this working now. But as always it needs to be more complex.

    the child records here all have a "type". I wish to not include one of these types... lets call it "type 1"

    I can do this by putting in the field in the query design and adding the criteria:
    Code:
    not type 1
    But in doing so It ruins the previous work of combining these records and splits them back up haha.

    a work around could be 2 querys.... one to not include "type 1" then use that as a record source. But I was wondering if you think its possible in one query.

  9. #9
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Sounds like you need two queries. If an element of the Sum includes records with a type value equal to 1, then you will need to sum on a separate query.

  10. #10
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    That's what I thought, Thanks for that

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

Similar Threads

  1. Replies: 4
    Last Post: 07-11-2014, 07:33 AM
  2. Calculating the total number
    By billylids5 in forum Forms
    Replies: 1
    Last Post: 04-27-2014, 04:06 AM
  3. Calculating Total on the report
    By Natella in forum Reports
    Replies: 5
    Last Post: 11-12-2013, 11:08 AM
  4. Replies: 1
    Last Post: 06-09-2012, 05:27 PM
  5. Need help with calculating Time total
    By Monoceros in forum Reports
    Replies: 1
    Last Post: 04-20-2009, 12:44 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