Aggregating a calculated field in TClientDataset - delphi

Is it possible to add an aggregate field over a calculated field?
Suppose there is a cds with following fields:
ID(autoincrement)
Name(string)
Price(float)
Quantity(integer)
Total(integer) - calculated field - Price * Quantity
and I want to add an agregate to get the sum of Total column. Is it possible?

Yes, that is possible if you change the calculated field to an InternalCalc field. The calculation is still done in the OnCalcFields event, but you have to check the state for InternalCalc when you make the calculation for that field.

Related

Default Aggregation on Tableau Calculated Field that uses Count

If I create a calculated field in Tableau like COUNTD([Account ID])/10, I cannot set a default aggregation on that field. However, if it is just something like SUM([# of Accounts])/10 then it will allow it. So my question is how can I set up the calculated field so that I can do a default aggregation when the calculation includes COUNTD?

Tcxgriddbtableview - Sum several columns in a certain row

I have a tcxgriddbtableview with multiple columns for amounts. I want to include subtotals in each row. Is it possible to define a column in such a way that it automatically totals several columns? Totalling already happens in SQL, but it should also happen dynamically when the user changes a value in a column of the table.
I'm looking for a property of the tcxgriddbtableview which takes over this function. There must be an easy way to do this, right?

Adding calculated fields to Google-Sheets form results

I'm taking data with a Google Spreadsheet form.
But for grouping puproses I want to add a column in the result-table with the weeknumber.
I also want a calculated field in my result-table.
Is this even possible? And what is the best way to accomplish this?
edit: hope this works.
this is the spreadsheet generated (and filled) by the form. Not the real one, just an example one.
https://docs.google.com/spreadsheets/d/1WXqNiP9EIx3lA0ND1ysFitfN9QVEGVXY2SI5cHF57oA/edit?usp=sharing
As said, I would like to be able to add a weeknumber field, and get a calculated field (total (Amount * Price))
The Calculated field can propabably be achieved with a query on a second Sheet. But I can't use a 'Weeknum()' in a query and group by it.
For the week number, paste in the first cell of the column of your choice (e.g. E2):
=arrayformula(WEEKNUM(A2:A))
For the calculated product field, e.g. in F2:
=ARRAYFORMULA(C2:C*D2:D)
The results of the array formulas will automatically update when new form responses come into the spreadsheet.

How to refer to calculated field from another calculated field in google sheets pivote?

I have a pivote table with two calculated fields. Is there any solution to refer this fields when i creating new calculated field ?
For example i have:
CalculatedField1
=SUM(arrayformula('sourceCol1'))
CalculatedField2
=AVERAGE(arrayformula('sourceCol2'))
Is there any way to multiply them like this?
='CalculatedField1'*'CalculatedField2'

DELPHI: Put calculated value into a master detail where details are in a grid

I have created a master-detail relation using ClientDataSets (Service & Addons). The Services are displayed in a DBLookupComboBox (cboServices) and once a service is selected the Addons are displayed in DBGrid (grdMain).
The Addons has a checkbox to indicate the Addon is selected, a name field, a quantities field that the user can change, a unit price field and a total price field.
I have created a OnQuantityChange method to update the total price using the unit price and quantity but how do I get the actual data from the row to do the updating? How do I reference the various fields in order to do something like the following:
grdMain.GetActiveRow.Column['TotalPrice'] :=
grdMain.GetActiveRow.Column['UnitPrice'] * grdMain.GetActiveRow.Column['Quantity'];
You can do that easily using calculated fields. I suggest you look at the following article for a detailed example with client dataset. Just search the article for calculated fields, you will find what you need.
TClientDataset example

Resources