Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: How to Subquery Correctly Post Reply Post New Topic
Author Message
mjefferson
Newbie
Newbie


Joined: 03 Apr 2012
Online Status: Offline
Posts: 5
Quote mjefferson Replybullet Topic: How to Subquery Correctly
     Posted: 19 Apr 2012 at 10:00am

Simplified version of my situation:

Table: Customer
Fields:
CustomerID
CustomerLocation (US or Canada)
 
Table: Transactions
Fields:
TransactionID
TransactionDate
CustomerID
TransactionAmount
ProductCategory
 
Sales department wants to set up a report that runs each morning and produces a report of total sales of the previous day by product category and customer location.  (It's an assignment, not my specs.)
 
Fields:
TransactionDate (group by)
ProductCategory (group by)
Sum of TransactionAmount where CustomerLocation = 'US'
Sum of TransactionAmount where CustomerLocation = 'Canada'
 
I could write this in SQL in a minute, but I am fairly new to Crystal.  I tried adding a Command to via Database Expert for each location - wrote the SQL and dragged the fields, but, despite having where statements for CustomerLocation in my Commands, both fields are coming up with the total Sum of TransactionAmount by ProductCategory and Date. 
 
I've been flipping through Crystal Reports 2008: The Complete Reference to try to figure out how to do this.  I'm sure there is an easier way with Crystal formulas.
 
Thanks for any help.  I am going to a couple Crystal training session in the next month - hopefull I'll be able to start answering questions someday. 


Edited by mjefferson - 19 Apr 2012 at 10:01am
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 19 Apr 2012 at 10:18am
for conditional sums you can use
shared variable formulas or
Running Total Fields or
Sometimes formula fields to convert the data at the row level that can then be summed
e.g
//us_customers
if table.customerlocation='US' then table.transaction amount
sum(@us_Customers)
//canada_customers
if table.customerlocation='Canada' then table.transaction amount
sum(@canada_Customers)


Edited by DBlank - 19 Apr 2012 at 10:18am
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum