[Easy] Report: TotalCost/qty

Hi In table1 i have two records, TotalCost and Qty What im trying to do is create a variable that is TotalCost/Qty Like I said, this is as basic as it gets.

I’ve inserted the code below into a Method on my report: Display CostprQty() { if (table1.Qty) { return table1.TotalCost/ table1.Qty; } else { return 0; } }

Display is probably not the right way to go, and if your still wondering, im not a programmer…[^] Any ideas?

You have a table that has two fields? Display is probably the only way. If you wanted to have Total Cost and TotalQty, as separate fields, then you can do this through MorphX, you don’t have to do any coding. But in your case display is a must :slight_smile: The easiest way to do this is to create display method in appropriate section of your report: display real CostprQty() { if (table1.Qty) return table1.TotalCost/ table1.Qty; else return 0; } And just drag the method name to your section and MorhpX will create proper control in your report.

Thanks! You are correct; Fields, not records. Tthere are 45 different fields in the table. Im only going to use a couple of them on my report. your suggestion creates an error (translated from norwegian): the table does not contain this field which is weird since the field does exist, however do i need to declare anything under classDeclaration Again; thanks Do i insert the method at the root or under “Query”?

You can insert method in appropriate Report node (Header, Footer, Body, etc.). The way to reference fields is . It would be best that you send me XPO file and I will try help.

I finally got it, turns out that I was refering to table(table1) not tablename(table1_1). Thanks, you’ve been a great help. Tutgual