Quantcast
Channel: DevExpress Support Center (Examples)
Viewing all articles
Browse latest Browse all 7205

How to use aggregate functions in Calculated Field expressions

$
0
0
This example illustrates how to calculate field values dynamically based on a group aggregated value. The following syntax is used in this case: [collection][condition].Function([Field])
To calculate a group sum (for example), use the approach from the How to conditionally suppress summary footer cell painting by using formatting rules code example. Please note that you can use the '^' symbol in expressions to refer to a currently processed data record.

In this code example the following expressions were used:

calcUnitsInStockSum
[][[CategoryID] == [^.CategoryID]].Sum([UnitsInStock])

calcUnitsInStockPercentage
[UnitsInStock] / [calcUnitsInStockSum]


See also:
How to calculate a weighted average function
Question Comments

Added By: Scott Gross at: 7/27/2016 10:29:43 AM    Could you update this example to include a better description of the expression used for the calculated field? possibly adding it to the code here instead of having to download the sample and inspect the Designer.cs file?Added By: Olga (DevExpress Support) at: 7/27/2016 12:41:36 PM    Hello Scott,
Thank you for your feedback! I agree that additional details may be useful in this description. I've updated it accordingly.
Please feel free to contact us in case of further difficulties.Added By: Scott Bogash 1 at: 8/12/2016 12:39:24 PM    I have found a problem with how the currently processed data record works when a property is renamed using IDisplayNameProvider.  It is not mapping from the renamed property back to the actual property name in the condition

From the winforms report demo, open the IList Data Source report in the designer.  Create a calculated field to count the number of Fish Categories using the expression editor you end up with the expression
[][[Fish Category]==[^.Fish Category]].Count().  This does not work. 

The actual property name for "Fish Category" is Category, so if I manually change the expression to
[][[Fish Category]==[^.Category]].Count()  This works correctly.





Added By: Jannet (DevExpress Support) at: 8/12/2016 2:43:33 PM    

Hello,

I've created a separate ticket on your behalf (T414525: Calculated fields - The currently processed data record is not recognized by a custom field name supplied through the IDisplayNameProvider interface implementation). It has been placed in our processing queue and will be answered shortly.


Viewing all articles
Browse latest Browse all 7205

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>