Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help logic

Status
Not open for further replies.

zsyed

MIS
Dec 25, 2011
73
CA
I've a scenario where I need summary by account group. here are two tables that I need to connect.
1) journallines having fields glaccountid and amount
2) accountgroup having fields groupid, glaccountidm, glaccountidl and glaccountidoh
(m-material, l-labour and oh-overhead)
journallines can have at any point of time (each record) either of glaccountidm, glaccountidl and glaccountidoh and amount. I would like to summarize information by account group for each category (m, l and oh). How do I connect tables and summarize data. If I'm vague in exaplining the scenario then please let me know.
many thanks in advance.
 
If I understand you correctly, the journallines.glaccountid value can be found in accountgroup.glaccountidm, accountgroup.glaccountidl, or glaccountidoh, is that correct?

I think your best bet for setting this up is going to be to use a Command instead of the tables because Crystal is not going to let you link the table correctly. A Command is just a SQL Select statem/ent. You will probably have to tweak this, but your command would look something like this (this assumes that glaccountidm, glaccountidl, and glaccountidoh will ALL always have values in them):

Code:
Select
  ag.groupid,
  ag.groupname,
  sum(case when jl.glaccountid = ag.glaccountidm then jl.amount else 0 end) as material_amount,
  sum(case when jl.glaccountid = ag.glaccountidl then jl.amount else 0 end) as labor_amount,
  sum(case when jl.glaccountid = ag.glaccountidoh then jl.amount else 0 end) as overhead_amount
from accountgroup as ag
  left join journallines jl on 
    jl.glaccountid = ag.glaccountidm or
    jl.glaccountid = ag.glaccountidl or
    jl.glaccountid = ag.glaccountidoh
group by ag.groupid, ag.groupname

This will do your summaries for you instead of having Crystal summarize the data.

A couple of things to note when working with commands:

1. You want to try write a query that will return ALL of the data for your report, if possible. When you link a command to a table or use multiple commands, Crystal will pull in all of the data from both and then do the join in memory.

2. If you need to filter the data, you need to do that in the where clause of the command. This also means that if you're using a parameter, you need to create the parameter IN THE COMMAND and not in the report.

-Dell

DecisionFirst Technologies - Six-time SAP BusinessObjects Solution Partner of the Year
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top