Reputation: 55
I know pxformula could do it, but pxformula only accepts two argument parameters. how can i add (sum) multiple fields of the same DAC? can i nest it?
thanks. some working examples would be appreciated, some other methods would also be appreciated.
Upvotes: 0
Views: 1672
Reputation: 31
I know this post is old, but I have been stuck on this for a while. I finally found a simple solution using [PXFormula] by nesting ADD's. I had made a new grid screen and I wanted the final column to total all the other columns. MY DAC’s :
one,two,three,four,five,six,seven,eight,nine,ten,eleven,twelve
The solution:
[PXFormula(typeof(Add<Add<Add<Add<Add<Add<one, two>,
Add<three, four>>, Add<five, six>>, Add<seven, eight>>,
Add<nine, ten>>, Add < eleven, twelve >>), typeof(SumCalc<total>))]
[PXDBDecimal()]
[PXUIField(DisplayName = "Total", Enabled = false)]
public virtual Decimal? Total { get; set; }
public abstract class total : PX.Data.BQL.BqlDecimal.Field<total> { }
Upvotes: 3
Reputation: 6778
As suggested in another answer, PXFormula can be used to perform a multi field calculation. However, PXFormula always assigns calculated value to the field it decorates.
PXUnboundFormulaAttribute might be a better approach in case you don't need to store calculated value in any field:
[PXUnboundFormulaAttribute(typeof(Switch<Case<Where<GLTranDoc.debitAccountID, IsNotNull>, GLTranDoc.curyTranTotal>, Sub<GLTranDoc.curyTaxAmt, GLTranDoc.curyInclTaxAmt>>),
typeof(SumCalc<GLDocBatch.curyDebitTotal>))]
For additional examples on the PXUnboundFormulaAttribute, please check Example 7.3: Adding Conditional Calculation of Aggregated Values in the T200 developer class guide at Acumatica University or Acumatica Open University
Upvotes: 1
Reputation: 5623
If you do a code search on PXFormula you should find many examples. I usually search the code found in your site/App_data/CpdeRepository directory if you have access to a local site.
If you are looking to perform a multi field calculations, you nest your Add, Sub, Mult, Div, etc. calls.
Here are some examples from my search on "PXFormula" or "Mult<" or "Add<":
Found in ARTranRUTROT.CuryRUTROTTotal, this example will subtrack curyExtPrice from curyDiscAmt and add curyRUTROTTaxAmountDeductible (unless null use zero)
[PXFormula(typeof(Add<Sub<ARTran.curyExtPrice, ARTran.curyDiscAmt>,
IsNull<curyRUTROTTaxAmountDeductible, decimal0>>))]
Found in GLTaxTran.CuryExpenseAmt. This example again uses multiple fields in the calculation all nested.
[PXFormula(typeof(Mult<Mult<GLTaxTran.curyTaxableAmt,
Div<GLTaxTran.taxRate, decimal100>>, Sub<decimal1,
Div<GLTaxTran.nonDeductibleTaxRate, decimal100>>>), null)]
Upvotes: 0