Conditional Sum

edited August 2008 in FastReport 4.0
Hello,

Is it possible to do the following in FR 4.0:

Data table

[paytype]___[payrecieved]
1 __________ 100
2 __________ 200
1 __________ 300
2 __________ 500

I want the report to show the following:

[Paytype 1] [Paytype 2]
400 __________ 700

So basically i need to do:

For the first column
If paytype = 1 then sum (payrecieved)

for the second column
if paytype = 2 then sum (payrecieved)

Thank You

Comments

  • edited 6:22PM
    I've tried this:

    [IIF ([<frOfficeIncome."clipaymethod">=0], SUM(<frOfficeIncome."clipayrec">,MasterData1,2),0)]

    but this does not work, i get an Invalid Variant Operation

    also tried like this:
    [IIF ([<frOfficeIncome."clipaymethod">=0], SUM(<frOfficeIncome."clipayrec">,MasterData1,1),0)]

    and like this:

    [IIF ([<frOfficeIncome."clipaymethod">=0], SUM(<frOfficeIncome."clipayrec">,MasterData1),0)]
  • gordkgordk St.Catherines On. Canada.
    edited 6:22PM
    create 2 typed variables on the code page
    Var
    totpaytype1,totpaytype2: extended;
    in the empty block initialize the var to 0.00
    begin
    totpaytype1 := 0.00;
    totpaytype2:= 0.00;
    end.
    in the obp event of the databand writ code to add the value of the datfield to the variable.
    begin
    if <datsetname."paytype"> = 1 then totpaytype1 := totpaytype1 + <datasetname."payrecieved'>;
    if <datsetname."paytype"> = 2 then totpaytype2 := totpaytype2 + <datasetname."payrecieved'>;
    end;
    you can then display the variables in any textobject using [ ] around the variablename.
  • edited 6:22PM
    Thank you very much,

    I was just wondering what you think is more efficient method to do these calculations a) the report level or [img]style_emoticons/<#EMO_DIR#>/cool.gif" style="vertical-align:middle" emoid="B)" border="0" alt="cool.gif" /> at the sql level? meaning if i change the query to add the following: select client_name, case when paytype = 1 then payrecieved else 0 as paytype1, case when paytype = 2 then payrecieved else 0 as paytype2, ... Just wondering, but thank you again for the swift response it's much appreciated.[/img]
  • gordkgordk St.Catherines On. Canada.
    edited 6:22PM
    i would probable use an entirely different way.
    first just a standard select query to display the data records then in a in the footer or summary band
    use a dbcrosstab to do your grouping using the same query.

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.