Yes, here it is. I will certainly appreciate any suggestions!
SELECT tblServCodes.ServCode, tblServCodes.ServCodeRate,
tblServicesProvided.UnitsUsed, tblServicesProvided.CalMonth,
tblContracts.InvType, tblServicesProvided.ContractName,
IIf([CalMonth]="July",[ServCodeRate]*[UnitsUsed],0) AS JulInv,
IIf([CalMonth]="August",[ServCodeRate]*[UnitsUsed],0) AS AugInv,
IIf([CalMonth]="September",[ServCodeRate]*[UnitsUsed],0) AS SepInv,
IIf([CalMonth]="October",[ServCodeRate]*[UnitsUsed],0) AS OctInv,
IIf([CalMonth]="November",[ServCodeRate]*[UnitsUsed],0) AS NovInv,
IIf([CalMonth]="December",[ServCodeRate]*[UnitsUsed],0) AS DecInv,
IIf([CalMonth]="January",[ServCodeRate]*[UnitsUsed],0) AS JanInv,
IIf([CalMonth]="February",[ServCodeRate]*[UnitsUsed],0) AS FebInv,
IIf([CalMonth]="March",[ServCodeRate]*[UnitsUsed],0) AS MarInv,
IIf([CalMonth]="April",[ServCodeRate]*[UnitsUsed],0) AS AprInv,
IIf([CalMonth]="May",[ServCodeRate]*[UnitsUsed],0) AS MayInv,
IIf([CalMonth]="June",[ServCodeRate]*[UnitsUsed],0) AS JunInv,
Sum([JulInv]+[AugInv]) AS Amt, tblServicesProvided.PTLRegWages,
tblServicesProvided.PTLPDO, tblServicesProvided.PQARegWages,
tblServicesProvided.FICA, tblServicesProvided.TaxOther,
tblServicesProvided.WComp, tblServicesProvided.GroupIns,
tblServicesProvided.LiabilityIns, tblServicesProvided.Match401K,
tblServicesProvided.Travel, tblServicesProvided.LocalOfficeEx,
tblServicesProvided.COOverhead, tblServicesProvided.CorpAdmExp,
tblServicesProvided.TotDirectExp, tblServicesProvided.TotIndExp,
tblServicesProvided.TotExpense, tblServicesProvided.TotNonUCRClaim,
tblServicesProvided.[PRCSS-Reg], tblServicesProvided.[PRCSS-PDO],
tblServicesProvided.NonCapExp
FROM (tblServicesProvided LEFT JOIN tblContracts ON
tblServicesProvided.ContractName = tblContracts.ContractName) LEFT JOIN
tblServCodes ON tblServicesProvided.ServCode = tblServCodes.ServCode
GROUP BY tblServCodes.ServCode, tblServCodes.ServCodeRate,
tblServicesProvided.UnitsUsed, tblServicesProvided.CalMonth,
tblContracts.InvType, tblServicesProvided.ContractName,
tblServicesProvided.PTLRegWages, tblServicesProvided.PTLPDO,
tblServicesProvided.PQARegWages, tblServicesProvided.FICA,
tblServicesProvided.TaxOther, tblServicesProvided.WComp,
tblServicesProvided.GroupIns, tblServicesProvided.LiabilityIns,
tblServicesProvided.Match401K, tblServicesProvided.Travel,
tblServicesProvided.LocalOfficeEx, tblServicesProvided.COOverhead,
tblServicesProvided.CorpAdmExp, tblServicesProvided.TotDirectExp,
tblServicesProvided.TotIndExp, tblServicesProvided.TotExpense,
tblServicesProvided.TotNonUCRClaim, tblServicesProvided.[PRCSS-Reg],
tblServicesProvided.[PRCSS-PDO], tblServicesProvided.NonCapExp;
--
Nona
Duane Hookom said:
Can you provide all of your SQL view for the query? It might help to get a
better understanding of your records and full specs for the query.
--
Duane Hookom
Microsoft Access MVP
:
Thanks for replying. And especially for the tip about the 3rd argument. I
fixed that right away.
However, the AllMthsInv formula doesn't give me what I need. It gives the
result per record for all the months.
The query expression I gave as an example calculates all the invoices that
were made in July, so that I have a total that were invoiced for July.
JulInv: IIf([CalMonth]="July",[ServCodeRate]*[UnitsUsed],0)
The next step is to get a total for the year.
I don't understand why the query won't total the amounts found in the
expressions, as in:
[JulyInv]+[AugInv]+[SepInv], etc., using the names in each month's expression.
--
Nona
:
It looks like you could use a crosstab query rather than a bunch of similar
expressions. If you want to include all months, why not just use:
AllMthsInv: [ServCodeRate]*[UnitsUsed]
Your IIf()s are also missing the 3rd argument which I assume should be
either 0 or Null.
JulInv: IIf([CalMonth]="July",[ServCodeRate]*[UnitsUsed], Null)
--
Duane Hookom
Microsoft Access MVP
:
I have a query that calculates the amount invoiced each month in a query:
For Instance:
JulInv: IIf([CalMonth]="July",[ServCodeRate]*[UnitsUsed])
AugInv: IIf([CalMonth]="August",[ServCodeRate]*[UnitsUsed])
Could someone tell me how can I get the query to give me a total for all the
months?
I tried this expression but it didn’t work: YearAmt: Sum([JulInv]+[AugInv])
Thanks in advance for your help!