我的详细信息部分中有3列:
如果类型为 debit ,我希望我的公式字段总计减去该值,并在 credit 时添加该值。逻辑在C ++中看起来像这样。如何在Crystal语法中重写它?
if(type=="credit")
total = total+balance
else if((type=="credit")
total = total-balance;
答案 0 :(得分:1)
您可以尝试使用水晶报告公式
If {type} = "credit" Then
{total} := {total} + {balance}
Else If {type} = "debit" Then
{total} := {total} - {balance}
或者,您可以在sql query
中编写案例陈述以获取updated_total
SELECT type, total,balance.....,
CASE
WHEN type ="credit" THEN (total + balance)
WHEN type ="debit" THEN (total - balance)
END as updated_total
FROM Datatable ;
答案 1 :(得分:0)
尝试创建名为UpdatedTotal
的公式字段并输入以下代码:
If {type} = "debit" Then
{total} - {balance}
Else If {type} = "credit" Then
{total} + {balance}
然后只需将公式字段放入报告中的任何位置即可显示。
在Crystal中,无需分配更新的总值:此新字段会自动显示更新的总计,并可通过名称引用{@UpdatedTotal}
在其他计算中使用。