Access 2002-budgets and expenses

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm unable to develop the proper queries that result in a report of 100% of
budgets by account number and program that also include any expenses. One
issue is that it is possible to have an expense without a budget and a budget
without an expense. I've created two queries that give results for each
scenario, but I don't know how to set up the final query that gives me 100%
of budgeted amount and 100% of actual expenses by account number and program
for the report. It sounds easy but has not been.
 
Dear Donna:

It seems to me the clue to your problem is in your statement:

"it is possible to have an expense without a budget and a budget
without an expense."

This is virtually a prescription for the need to have a full outer
join. If you are using Access Jet, which does not have full outer
joins, it will take a small amount of additional effort.

In the case of Jet, you can use a UNION of a LEFT JOIN and a RIGHT
JOIN. I find a variation of this to be best, which is to use a UNION
ALL (which is faster) and filter out the otherwise duplicated rows
from the RIGHT JOIN portion, those being the rows that have both and
expense and a budget.

That's the theory anyway. If some of this seems new or foreign to
you, well that's OK. Having covered the ground in theory, we can work
our way up to it in practice. This may take a day or two of
correspondence to accomplish. Assuming for the moment you may need
this help, here's what I'd ask you to do to get it started.

Please post a query with a simple INNER JOIN that shows just what you
want but limited to those rows that have both budget and expense data.
We can work forward from there. OK?

If you are using MSDE or some other database than Jet, please specify.

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts
 
Thank you, Tom. As I read other posts last night I saw Union as a
possibility, but am new to the concept. I am using Jet and I am beginning to
understand SQL. I have many manuals as well. I will attempt to create a Union
ALL by copying the SQL from the two queries that work into a new Union query.
I'll use a manual for tips. I'll reply back for the next details of my
progress. If I don't get the Union ALL to work in the first step, I'll post
it for you in my next response to clean up.

DonnaG
 
Dear Donna:

I congratulate you on your attitude! By grabbing a concept and doing
all you can to run with it yourself you will likely learn the greatest
amount possible. Before we know it, you'll be the one in this
newsgroup answering questions, not asking them.

But don't be embarassed now to come back for more help if needed.
That's a valid part of the process, too!

I deliberately frame my answers to initially be strong on concepts and
light on details in the hope that someone like you will gain the
maximum by picking up the concepts and running with them. But it
rarely works out that way. That's why I'm so proud of you.

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts
 
Thank you for your comments, Tom. As I was considering my "attitude" I
realized you may save me lots of time. When I looked in the manuals I see
very little on Union queries. My first query that works uses 3 queries to
arrive at the results as follows. When I pasted the second query with it with
Union All in between I got the error message that [Account no-...].[Expend
Code] could refer to more than one table listed in the from clause. I do have
only one table, but the three queries all use it to limit their results. Here
is the query that results in "if no expense, then no budget". I didn't know
if you need to see the one that results in "if no budget, then no expense".
Thank you so much for your help.

SELECT DISTINCTROW [ProgramExpense Period Summary Query].[SumOfClaim Amt],
[ProgramBudgets Period Query].BudgetAmt, [Account No-Keys in General
Fund].[Expend Code], ProgramCodes.Program, [ProgramExpense Date Range Summary
Query].[SumOfClaim Amt], [Account No-Keys in General Fund].[Acct Desc],
ProgramCodes.ProgDesc, [Object Groups].SortOrder, [Account No-Keys in General
Fund].ObjectGroup, [Object Groups].Description, [Account No-Keys in General
Fund].[Fund No]

FROM (([Account No-Keys in General Fund] LEFT JOIN [Object Groups] ON
[Account No-Keys in General Fund].ObjectGroup = [Object Groups].ObjectGroup)
INNER JOIN (([ProgramExpense Period Summary Query] LEFT JOIN [ProgramExpense
Date Range Summary Query] ON ([ProgramExpense Period Summary Query].[Expend
Code] = [ProgramExpense Date Range Summary Query].[Expend Code]) AND
([ProgramExpense Period Summary Query].Program = [ProgramExpense Date Range
Summary Query].Program)) LEFT JOIN ProgramCodes ON [ProgramExpense Period
Summary Query].Program = ProgramCodes.Program) ON [Account No-Keys in General
Fund].[Expend Code] = [ProgramExpense Period Summary Query].[Expend Code])
LEFT JOIN [ProgramBudgets Period Query] ON ([ProgramExpense Period Summary
Query].Program = [ProgramBudgets Period Query].PROGRAM) AND ([ProgramExpense
Period Summary Query].[Expend Code] = [ProgramBudgets Period Query].[EXPEND
CODE])

ORDER BY [Account No-Keys in General Fund].[Expend Code],
ProgramCodes.Program, [Object Groups].SortOrder;
 
Dear Donna:

Whew! Can we cut down your query a bit? My eyes are wearing out!

SELECT DISTINCTROW PEP.[SumOfClaim Amt], PBP.BudgetAmt,
GF.[Expend Code], PC.Program, PER.[SumOfClaim Amt],
GF.[Acct Desc], PC.ProgDesc, OG.SortOrder, GF.ObjectGroup,
OG.Description, GF.[Fund No]

FROM (([Account No-Keys in General Fund] GF
LEFT JOIN [Object Groups] OG ON GF.ObjectGroup = OG.ObjectGroup)
INNER JOIN (([ProgramExpense Period Summary Query] PEP
LEFT JOIN [ProgramExpense Date Range Summary Query] PER
ON (PEP.[Expend Code] = PER.[Expend Code])
AND (PEP.Program = PER.Program))
LEFT JOIN ProgramCodes PC ON PEP.Program = PC.Program)
ON GF.[Expend Code] = PEP.[Expend Code])
LEFT JOIN [ProgramBudgets Period Query] PBP
ON ([PEP.Program = PBP.PROGRAM)
AND (PEP.[Expend Code] = PBP.[EXPEND CODE])

ORDER BY GF.[Expend Code], PC.Program, OG.SortOrder;

Now, what I have done is to introduce aliasing for those long table
names, and added some indentation and line formatting. Hopefully I
didn't screw it up. Anyway, this improves the readability for me.

Could we look at all your LEFT JOINs for a moment. In each case, is
it the case that there are rows in the table to the left that don't
have child / dependent rows in the table on the right?

For example, are there rows in GF (General Fund) with values in the
ObjectGroup column where you don't have a corresponding ObjectGroup
row in [Object Groups]?

The same question applies to the other LEFT JOINS you have.

The answer to this can best be found in your database designs.

What I need to know primarily is where to divide this query work into
two parts, one for the expenses side and one for the budget side.
Perhaps it would be especially useful to create separate queries that
perform the two sides independently, given the complexity of what you
have so far.

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts


Thank you for your comments, Tom. As I was considering my "attitude" I
realized you may save me lots of time. When I looked in the manuals I see
very little on Union queries. My first query that works uses 3 queries to
arrive at the results as follows. When I pasted the second query with it with
Union All in between I got the error message that [Account no-...].[Expend
Code] could refer to more than one table listed in the from clause. I do have
only one table, but the three queries all use it to limit their results. Here
is the query that results in "if no expense, then no budget". I didn't know
if you need to see the one that results in "if no budget, then no expense".
Thank you so much for your help.

SELECT DISTINCTROW [ProgramExpense Period Summary Query].[SumOfClaim Amt],
[ProgramBudgets Period Query].BudgetAmt, [Account No-Keys in General
Fund].[Expend Code], ProgramCodes.Program, [ProgramExpense Date Range Summary
Query].[SumOfClaim Amt], [Account No-Keys in General Fund].[Acct Desc],
ProgramCodes.ProgDesc, [Object Groups].SortOrder, [Account No-Keys in General
Fund].ObjectGroup, [Object Groups].Description, [Account No-Keys in General
Fund].[Fund No]

FROM (([Account No-Keys in General Fund] LEFT JOIN [Object Groups] ON
[Account No-Keys in General Fund].ObjectGroup = [Object Groups].ObjectGroup)
INNER JOIN (([ProgramExpense Period Summary Query] LEFT JOIN [ProgramExpense
Date Range Summary Query] ON ([ProgramExpense Period Summary Query].[Expend
Code] = [ProgramExpense Date Range Summary Query].[Expend Code]) AND
([ProgramExpense Period Summary Query].Program = [ProgramExpense Date Range
Summary Query].Program)) LEFT JOIN ProgramCodes ON [ProgramExpense Period
Summary Query].Program = ProgramCodes.Program) ON [Account No-Keys in General
Fund].[Expend Code] = [ProgramExpense Period Summary Query].[Expend Code])
LEFT JOIN [ProgramBudgets Period Query] ON ([ProgramExpense Period Summary
Query].Program = [ProgramBudgets Period Query].PROGRAM) AND ([ProgramExpense
Period Summary Query].[Expend Code] = [ProgramBudgets Period Query].[EXPEND
CODE])

ORDER BY [Account No-Keys in General Fund].[Expend Code],
ProgramCodes.Program, [Object Groups].SortOrder;

Tom Ellison said:
Dear Donna:

I congratulate you on your attitude! By grabbing a concept and doing
all you can to run with it yourself you will likely learn the greatest
amount possible. Before we know it, you'll be the one in this
newsgroup answering questions, not asking them.

But don't be embarassed now to come back for more help if needed.
That's a valid part of the process, too!

I deliberately frame my answers to initially be strong on concepts and
light on details in the hope that someone like you will gain the
maximum by picking up the concepts and running with them. But it
rarely works out that way. That's why I'm so proud of you.

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts
 
Thank you for your response. I'm a relatively new user and self-taught from 5
different manuals. I agree that the names of my queries are long. I have so
many different versions of the queries while I'm testing theories that I need
to be descriptive in the titles as well as properties to be sure I'm in the
correct one. Once I get everything working they are simplified and I delete
those that don't work right. I have since solved a minor issue with a
duplicate field name (SumOfClaim Amt) so I'll factor that into my feedback.

I'm not proficient in joins. I actually keep trying them various ways until
I get no outer join error messages and achieve the results that I want.

I think the following will answer your final question, beyond that I'm not
sure what you need to know for the Union query. Meanwhile, I'm still reading
everything I can about Union queries, but don't have all the concepts yet.

This query uses the results of 3 different queries to produce the data
needed for our periodic report. The other table fields were used in my
attempts to get valid results with fields to use in the report for sorting.
The one presented results in no budget if there is no expense.

For each program (PC.Program) and account number (GF.Expend Code):
PBP gives the budgets for the correct period -PBP.BudgetAmt
PEP gives the monthly or quarterly period expenses -PEP.SumOfClaim AmtMo
PER gives the fiscal year to date expenses -PER.SumOfClaim AmtFY

Do you need to see the 3 underlying queries or the query to be unioned that
gave the results with "If no budget, no expense"? Abbreviated, of course. I'm
still analyzing the differences between them to know what to focus on.


Tom Ellison said:
Dear Donna:

Whew! Can we cut down your query a bit? My eyes are wearing out!

SELECT DISTINCTROW PEP.[SumOfClaim Amt], PBP.BudgetAmt,
GF.[Expend Code], PC.Program, PER.[SumOfClaim Amt],
GF.[Acct Desc], PC.ProgDesc, OG.SortOrder, GF.ObjectGroup,
OG.Description, GF.[Fund No]

FROM (([Account No-Keys in General Fund] GF
LEFT JOIN [Object Groups] OG ON GF.ObjectGroup = OG.ObjectGroup)
INNER JOIN (([ProgramExpense Period Summary Query] PEP
LEFT JOIN [ProgramExpense Date Range Summary Query] PER
ON (PEP.[Expend Code] = PER.[Expend Code])
AND (PEP.Program = PER.Program))
LEFT JOIN ProgramCodes PC ON PEP.Program = PC.Program)
ON GF.[Expend Code] = PEP.[Expend Code])
LEFT JOIN [ProgramBudgets Period Query] PBP
ON ([PEP.Program = PBP.PROGRAM)
AND (PEP.[Expend Code] = PBP.[EXPEND CODE])

ORDER BY GF.[Expend Code], PC.Program, OG.SortOrder;

Now, what I have done is to introduce aliasing for those long table
names, and added some indentation and line formatting. Hopefully I
didn't screw it up. Anyway, this improves the readability for me.

Could we look at all your LEFT JOINs for a moment. In each case, is
it the case that there are rows in the table to the left that don't
have child / dependent rows in the table on the right?

For example, are there rows in GF (General Fund) with values in the
ObjectGroup column where you don't have a corresponding ObjectGroup
row in [Object Groups]?

The same question applies to the other LEFT JOINS you have.

The answer to this can best be found in your database designs.

What I need to know primarily is where to divide this query work into
two parts, one for the expenses side and one for the budget side.
Perhaps it would be especially useful to create separate queries that
perform the two sides independently, given the complexity of what you
have so far.

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts


Thank you for your comments, Tom. As I was considering my "attitude" I
realized you may save me lots of time. When I looked in the manuals I see
very little on Union queries. My first query that works uses 3 queries to
arrive at the results as follows. When I pasted the second query with it with
Union All in between I got the error message that [Account no-...].[Expend
Code] could refer to more than one table listed in the from clause. I do have
only one table, but the three queries all use it to limit their results. Here
is the query that results in "if no expense, then no budget". I didn't know
if you need to see the one that results in "if no budget, then no expense".
Thank you so much for your help.

SELECT DISTINCTROW [ProgramExpense Period Summary Query].[SumOfClaim Amt],
[ProgramBudgets Period Query].BudgetAmt, [Account No-Keys in General
Fund].[Expend Code], ProgramCodes.Program, [ProgramExpense Date Range Summary
Query].[SumOfClaim Amt], [Account No-Keys in General Fund].[Acct Desc],
ProgramCodes.ProgDesc, [Object Groups].SortOrder, [Account No-Keys in General
Fund].ObjectGroup, [Object Groups].Description, [Account No-Keys in General
Fund].[Fund No]

FROM (([Account No-Keys in General Fund] LEFT JOIN [Object Groups] ON
[Account No-Keys in General Fund].ObjectGroup = [Object Groups].ObjectGroup)
INNER JOIN (([ProgramExpense Period Summary Query] LEFT JOIN [ProgramExpense
Date Range Summary Query] ON ([ProgramExpense Period Summary Query].[Expend
Code] = [ProgramExpense Date Range Summary Query].[Expend Code]) AND
([ProgramExpense Period Summary Query].Program = [ProgramExpense Date Range
Summary Query].Program)) LEFT JOIN ProgramCodes ON [ProgramExpense Period
Summary Query].Program = ProgramCodes.Program) ON [Account No-Keys in General
Fund].[Expend Code] = [ProgramExpense Period Summary Query].[Expend Code])
LEFT JOIN [ProgramBudgets Period Query] ON ([ProgramExpense Period Summary
Query].Program = [ProgramBudgets Period Query].PROGRAM) AND ([ProgramExpense
Period Summary Query].[Expend Code] = [ProgramBudgets Period Query].[EXPEND
CODE])

ORDER BY [Account No-Keys in General Fund].[Expend Code],
ProgramCodes.Program, [Object Groups].SortOrder;

Tom Ellison said:
Dear Donna:

I congratulate you on your attitude! By grabbing a concept and doing
all you can to run with it yourself you will likely learn the greatest
amount possible. Before we know it, you'll be the one in this
newsgroup answering questions, not asking them.

But don't be embarassed now to come back for more help if needed.
That's a valid part of the process, too!

I deliberately frame my answers to initially be strong on concepts and
light on details in the hope that someone like you will gain the
maximum by picking up the concepts and running with them. But it
rarely works out that way. That's why I'm so proud of you.

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts


On Wed, 24 Nov 2004 07:49:15 -0800, DonnaG

Thank you, Tom. As I read other posts last night I saw Union as a
possibility, but am new to the concept. I am using Jet and I am beginning to
understand SQL. I have many manuals as well. I will attempt to create a Union
ALL by copying the SQL from the two queries that work into a new Union query.
I'll use a manual for tips. I'll reply back for the next details of my
progress. If I don't get the Union ALL to work in the first step, I'll post
it for you in my next response to clean up.

DonnaG

:

Dear Donna:

It seems to me the clue to your problem is in your statement:

"it is possible to have an expense without a budget and a budget
without an expense."

This is virtually a prescription for the need to have a full outer
join. If you are using Access Jet, which does not have full outer
joins, it will take a small amount of additional effort.

In the case of Jet, you can use a UNION of a LEFT JOIN and a RIGHT
JOIN. I find a variation of this to be best, which is to use a UNION
ALL (which is faster) and filter out the otherwise duplicated rows
from the RIGHT JOIN portion, those being the rows that have both and
expense and a budget.

That's the theory anyway. If some of this seems new or foreign to
you, well that's OK. Having covered the ground in theory, we can work
our way up to it in practice. This may take a day or two of
correspondence to accomplish. Assuming for the moment you may need
this help, here's what I'd ask you to do to get it started.

Please post a query with a simple INNER JOIN that shows just what you
want but limited to those rows that have both budget and expense data.
We can work forward from there. OK?

If you are using MSDE or some other database than Jet, please specify.

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts


On Tue, 23 Nov 2004 17:43:03 -0800, DonnaG

I'm unable to develop the proper queries that result in a report of 100% of
budgets by account number and program that also include any expenses. One
issue is that it is possible to have an expense without a budget and a budget
without an expense. I've created two queries that give results for each
scenario, but I don't know how to set up the final query that gives me 100%
of budgeted amount and 100% of actual expenses by account number and program
for the report. It sounds easy but has not been.
 
Tom,
It's time to quit for the holidays, and I just this minute solved the problem!

I've cleaned up my queries, query names, and field names. I have separate
queries that develop the monthly expenses and fiscal year expenses, then a
query that pulls in those two. That is the query that left joins to budget.
My next query reversed the joins. I pasted the SQL from each into the SQL of
the Union query. I first used Union ALL and got incorrect results, but Union
finally works perfectly.

Thank you for your help. All your comments led me to the right pages and
gave better understanding of what to focus on. I wish the books talked more
about Union queries. Microsoft Press Access 2003 Inside Out has been
extremely useful and I relied on the CD article "Understanding SQL".

I will now have a nice holiday. I hope you do, too.

DonnaG
 
Back
Top