Monthly and YTD totals (1 Viewer)

dkmoreland

Registered User.
Local time
Today, 07:10
Joined
Dec 6, 2017
Messages
129
I am trying to create a report that shows monthly totals and YTD totals. I also need to show monthly totals of jobs that were not approved.

Here's initial query:
Code:
SELECT [Carrier Release].[Job Number], [Carrier Release].Supplier, [Carrier Release].[Date Eval], [Carrier Release].Approved, [Carrier Release].[NCR Num], Year([Carrier Release].[Date Eval]) AS [year], Format([Date Eval],"mmm") AS [Month]
FROM [Carrier Release];

From here, I am using a crosstab query to give me my monthly breakdown:
Code:
TRANSFORM Count([Carrier Release Query].[Job Number]) AS [CountOfJob Number]
SELECT [Carrier Release Query].Supplier, Count([Carrier Release Query].[Job Number]) AS Total
FROM [Carrier Release Query]
GROUP BY [Carrier Release Query].Supplier
PIVOT [Carrier Release Query].Month;

That all works fine on the initial report. I need to add a supreport that gives monthly and YTD totals on records in the initial query where Approved = "no". Here's my query for that:
Code:
SELECT [Carrier Release Query].[Job Number], [Carrier Release Query].[Date Eval], [Carrier Release Query].Supplier, [Carrier Release Query].Month, [Carrier Release Query].Approved
FROM [Carrier Release Query]
WHERE ((([Carrier Release Query].Approved)="no"));

Here's the query that counts the number of records that were not approved:
Code:
SELECT Count([Carrier jobs with NCRs].[Approved]) AS CountOfApproved, [Carrier jobs with NCRs].[Supplier], [Carrier jobs with NCRs].[Month]
FROM [Carrier jobs with NCRs]
GROUP BY [Carrier jobs with NCRs].[Supplier], [Carrier jobs with NCRs].[Month];

I said all of that to ask this question - the subreport data does not have data for every month in the year - for example, there are no records for December. I need to leave a place for December data for next year - right now I'm getting an error that the field doesn't exist. It doesn't, since it is a calculated field that is returning no value.

Any advice on the best way to handle this? I need it to just show zero for the months where there is no value returned from the calculation.

I appreciate and all insight. The attached screen shots should provide a visual illustration of what I am doing.
 

Attachments

  • Initial crosstab results.PNG
    Initial crosstab results.PNG
    10.9 KB · Views: 207
  • jobs where approved is no.PNG
    jobs where approved is no.PNG
    19.9 KB · Views: 200
  • Count where approved is no.PNG
    Count where approved is no.PNG
    7.9 KB · Views: 202

plog

Banishment Pending
Local time
Today, 09:10
Joined
May 11, 2011
Messages
11,643
You can't create data where there is none....so make some. You will need a table that houses all the values you want to report on. Since you want to report on all months, you will need a table of those.

Then what you do is before you cross-tab, you include that table in your query. You LEFT JOIN from that table (e.g. Show all records from the month table) to whatever datasource you have now. You use the month from that new table and that will force it to show up. To convert the null value to 0, use NZ().
 

dkmoreland

Registered User.
Local time
Today, 07:10
Joined
Dec 6, 2017
Messages
129
I wonder if it would work to use an if statement in the report control - that basically says if the field doesn't exist, display a zero.
 

dkmoreland

Registered User.
Local time
Today, 07:10
Joined
Dec 6, 2017
Messages
129
You can't create data where there is none....so make some. You will need a table that houses all the values you want to report on. Since you want to report on all months, you will need a table of those.

Then what you do is before you cross-tab, you include that table in your query. You LEFT JOIN from that table (e.g. Show all records from the month table) to whatever datasource you have now. You use the month from that new table and that will force it to show up. To convert the null value to 0, use NZ().

I'm not sure I'm getting your full meaning. The monthly data is in a date format calculated field in the original query. If I put the months fields in a separate table, even with a join, how will this work when the field calculation in the original query returns a value other than null?
 

plog

Banishment Pending
Local time
Today, 09:10
Joined
May 11, 2011
Messages
11,643
A JOIN matches data between two tables:

Table1
MonthName, SalesTotal
January, 18
March, 22
May, 7

Table2
MonthName
January
February
...
December

You link those tables via MonthName. If you use an INNER JOIN (show matching records) the resulting query will produce 3 records (the ones in Table1). If you use a LEFT JOIN (showing all from Table2) the resulting query will produce 12 records (one for each month). Of course, 9 of those will have null SalesTotal values. You convert those to 0 values via the NZ function.
 

dkmoreland

Registered User.
Local time
Today, 07:10
Joined
Dec 6, 2017
Messages
129
Oh - ok. I see what you mean. I'll give that a try. Thanks so much for the additional explanation!
 

Users who are viewing this thread

Top Bottom