Crystal Reports - Selecting data in the first row to be used in a formula

旧城冷巷雨未停 提交于 2019-12-13 01:23:12

问题


I have a very basic report with no groups. The details consists of a number of numeric columns. I want to add a formula field which will use a field from the first row. Example:

(ColumnAFromCurrentRecord - ColumnBFromFirstRecord) / ColumnBFromFirstRecord

Can someone point me in the right direction?


回答1:


you need to extact the column b from first record. try below solution.

Note: This is not a tested solution as I at present I don't have CR.

create below formula Count and place in detail section:

Local NumberVar a;
a:=a+1;

This will number the rows starting from 1 to the last row.

Now create one more formula StoreB:

Share NumberVar b;

if {@Count}=1
then b:=columnb

This will store the value of columnb in first record in variable b

Now use where you want:

EvaluateAfter(@StoreB)
Shared NumberVar b;

(ColumnAFromCurrentRecord - b) / b

Let me know how it goes.




回答2:


1. Create a formula named AssignFirstValue and define it like this:

WhilePrintingRecords; 
Global StringVar strFirstValue := {MYDBNAME.MYSTRINGFIELD}; 

Put the AssignFirstValue formula in your Report Header and suppress it.

2. Create a formula named PrintFirstValue and define it like this:

WhilePrintingRecords; 
Global StringVar strFirstValue; 
strFirstValue 

Put the PrintFirstValue formula wherever you want to display the first value in your report.




回答3:


Video on Crystal Report formulas. http://youtu.be/bE0ikQfELV8



来源:https://stackoverflow.com/questions/22573250/crystal-reports-selecting-data-in-the-first-row-to-be-used-in-a-formula

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