How do I in Crystal Report sum data on a column where id is some number

Deadly 提交于 2019-12-13 04:06:33

问题


I am new to Crystal Reports and have been trying to figure this out for a while. I am running Crystal Reports XI. Please Help.

The data:
 john respMonitor    5
 abe  case mgmt      4   
 Cy   test1          4
 Claire respMonitor  5
 Moe   test3         2 
 Bob   case mgmt     8
 Lynn  respMonitor   4 
 Rick  test2         33
 Ray   test1         31
 Al    test1         24
 etc. 

I want to create the following data:

group           cost
 sumOfTests1_3      124.0  <====== want a sum of tests only
 respMonitor     5.0
 caseMgmt        7.0
 respMonitor     3
 respMonitor     2
 caseMgmt        4
 etc.

So I want to be able to only sum up the tests while leaving the other groups alone.

I created a sql expression field:
 {%testCM}
(
SELECT sum("Patient"."cost") From PatientTbl 
    Where "PatientTbl"."group"= 'test1' OR
    "PatientTbl"."group"= 'test2' OR
    "PatientTbl"."group"= 'test3' 
)

In my Record Selection I have:
 {PatientTbl.group} in ["respMonitor","case mgmt", "test1","test2","test3"]

I also created a formula field:
 If {PatientTbl.group} in ["test1", "test2","test3"] Then
      {%testCM}

Should there be an Else-block in the formula field to print out the rest? I don't see how to sum up only the costs for group "test" while leaving the other groups to still be printed out individually. Not sure where to go from here.

Thanks, John


回答1:


I don't think you need a SQL expression. Just add this formula and use it as your group expression and then sum the costs. A group with one cost will still show the right value.

if {PatientTbl.group} in ["test1", "test2","test3"] Then
    "Test1-3"
else
    {PatientTbl.group}



回答2:


one approach would be to create a sub report to do the sum for the tests and in main report after sub report insert one more section there place the field and write the supress condition for that section to supress when there are tests displayed.

supress condition would be:

if {PatientTbl.group} in ["test1", "test2","test3"] Then
true
else
    false


来源:https://stackoverflow.com/questions/29085299/how-do-i-in-crystal-report-sum-data-on-a-column-where-id-is-some-number

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!