Go back and use end total value in each record?

Hello

Is there a way in C/AL to go back to every record in a report and use the the grand total field to calculate the percentage of that particular record over the total value?

Im on Nav 2009.

Thanks

yes…

on AfterGetRecord()

you can define a parameter like total amount

I meant after I get every record and reach the end, I want to go back and add a field to each record because I want to use the total.

Hi,
Do you mean to say showing the subtotal on every age when the record ends ?

If you are using classic version then use trans footer and trans header

If you are using higher version then you need to play with groups.

No, I already have the subtotals.

I want to be able to use the grand total calculated at the end of the report and calculate percentages for each record based on it. Like in the picture below:

http://imgur.com/a/JbfQW

I think you can define a parameter for each percentage. Or you can use flowfield in header that sum up all amount in lines, then use that column to calculate percentages in report.

it’s difficult to have all items in footer.
but maybe you can use array to show all of them. :slight_smile:

Copy your dataitem - but without any layout. Then calculate the value in the first loop of the dataitem on the OnAfterGetRecord trigger like suggested above (remember also to copy all filters).

When you run the “original” dataitem (with the layout) then you already know the total.

Define a record variable of the table from which you need the total, calculate the sum of the field on OnPreReport or OnPreDataItem trigger and store this sum in a global decimal variable. Use this decimal variable’s value on OnAfterGetRecord trigger to calculate percentage for each record.

Hope this helps.

Good one [mention:35665616981c44478c4102929e7adf80:e9ed411860ed4f2ba0265705b8793d05] - I was just about to suggest that as an alternative. It just depends on what kind of value it is. If the value is a field on the dataitem, then this method is surely the easiest. Because then you can just use calcSum. If on the other hand, the data is calculated on each item, then it may not be possible, to do without looping it first.

[mention:61b2aa9ce72e429baa1ef43208ddbea4:e9ed411860ed4f2ba0265705b8793d05] “If on the other hand, the data is calculated on each item, then it may not be possible, to do without looping it first.” - True that! :slight_smile:

Thank you!
Will calcums work in PreReport?

Yes, calcsums works based on the Record variable of the table. The trigger doesn’t matter.

Please correct me if I am wrong, I hope not! :slight_smile:

It will, but it would not include any filters you might be setting later.

So I suggest that you use OnPreDataItem of the record you want to calculate.