Total in a query

matthewR
5StarLounger
Posts: 627
Joined: 03 Feb 2010, 15:02

Total in a query

Post by matthewR »

Is there anyway in a query to do something like the following:

Clientcontracts:total([FA_Total_Contracts]for[Client_Number])

I have a field - FA_Total_Contracts - that gives the contracts for each group. These groups are under one client. I would like to have a field that shows the contracts for the whole client or each client.

It looks something like:

Code: Select all

Client                     Group              Contracts        contracts per client
100                            1                     50                         123
100                            2                     40                         123
100                            3                     33                         123
200                           11                      5                          65
200                           12                     10                          65
200                           13                     50                          65
Can this be done in a query?
Last edited by HansV on 17 Sep 2010, 16:39, edited 1 time in total.
Reason: to display data in code tags

User avatar
HansV
Administrator
Posts: 78493
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Total in a query

Post by HansV »

You could use this definition:

Contracts per client: DSum("Contracts","NameOfTable","Client=" & [Client])

Subtitute the name of the table for NameOfTable. I have assumed that Client is a number field.
Best wishes,
Hans

matthewR
5StarLounger
Posts: 627
Joined: 03 Feb 2010, 15:02

Re: Total in a query

Post by matthewR »

I am getting an error. I am using the following:

Contracts per client: DSum("FA_Total_Contracts","TC_Workload","Client_Number=" & [Client_Number])

The Client_Number is a text field.

User avatar
HansV
Administrator
Posts: 78493
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Total in a query

Post by HansV »

For a text field, you need a slightly different version, since text values must be enclosed in quotes:

Contracts per client: DSum("FA_Total_Contracts","TC_Workload","Client_Number=" & Chr(34) & [Client_Number] & Chr(34))

Chr(34) is the double quote character ".
Best wishes,
Hans

matthewR
5StarLounger
Posts: 627
Joined: 03 Feb 2010, 15:02

Re: Total in a query

Post by matthewR »

Thanks Hans - that worked perfectly.