How to add a sum to a formula field in FastReports - report

I am trying to add a sum for a formula field, but it is not working. It works if I create a sum for a normal field, but not with a formula.
Can someone please help me with this ?
Thanks.

Related

how can I get category using summary()

When I get a summary in R, I get this instead of a list of the items. In this case, it should be HIGH/LOW/NORMAL, but I get length/ class/mode instead. is any setting off in my R? Please advise if you happen to know.

How to calculate average annual salary in libreoffice calc

I have salary data table from 10 years period. Every column has properly set data type (date for "B", number for "C" and "E".
I'm trying to write a formula to calculate average salary for every year. In column "E" I've manually entered all possible years and in column "F" should be an yearly average, according to year from "E".
So, my best try is this formula: =AVERAGEIF(YEAR(B2:B133);"="&E2;C2:C133)
Trying so calculate an average from column C, where year in date from column B equals a year in column E
But all I get is an error Err:504. Figured out, that problem is in YEAR(interval) part, but can't get what exactly...
Can someone point that out?
Thank you!
There are actually many possibilities to solve this.
#JvdV answer;
using an array formula with #JvdV solution;
using an array formula with a combination of AVERAGE() and IF();
using the SUMPRODUCT() function;
and surely many other solutions that I don't know about!
Please beware: I use , instead of ; as formula separator, according to my locale; adapt to your needs.
A side note on "array formulas"
This kind of formulas are applied by mandatory pressing the Ctrl + Shift + Enter key combination to insert them, not only Enter or Tab or mouse-clicking elsewhere on the sheet.
The resulting formula is shown between brackets {}, which are not inserted by the user but are automatically shown by the software to inform that this is actually an array formula.
More on array formulas i.e. on the LibreOffice help system.
Usually you cannot drag and drop array formulas, you have to copy-paste them instead.
Array formula with #JvdV solution
The solution of JvdV could be slighly modified like this, and then inserted as an array formula:
=AVERAGEIFS(C$2:C$133,YEAR($B$2:$B$133),"="&E2)
When you insert this formula with the Ctrl + Shift + Enter key combination, the software puts the formula into brackets, so that you see it like this: {=AVERAGEIFS(C$2:C$133,YEAR($B$2:$B$133),"="&E2)}
You cannot simply drag the formula down, but you can copy-paste it.
Array formula with a combination of AVERAGE() and IF():
For your example, put this formula in cell F2 (for the year 2010):
=AVERAGE(IF(YEAR($B$2:$B$133)=E2,$C$2:$C$133))
When you insert this formula with the Ctrl + Shift + Enter key combination, the software puts the formula into brackets, so that you see it like this {=AVERAGE(IF(YEAR($B$2:$B$133)=E2,$C$2:$C$133))}
You cannot simply drag the formula down, but you can copy-paste it.
SUMPRODUCT() formula:
My loved one...
Plenty of resources on the web to explain this formula.
In your situation, this would give:
=SUMPRODUCT($C$2:$C$133,--(YEAR($B$2:$B$133)=E2))/SUMPRODUCT(--(YEAR($B$2:$B$133)=E2))
This one you can drag down to your needs.
Unfortunately AVERAGEIF() expects a range reference instead of a calculated array. Therefor it will error out. That's the theory at least for Excel, and I expect this to be the same for LibreCalc.
One way around it is using the AVERAGEIFS() function and check against first and last days of the year, for example:
=AVERAGEIFS(C$2:C$133;B$2:B$133;">="&DATE(E2;1;1);B$2:B$133;"<="&DATE(E2;12;31))
Drag the formula down.

Finding values for a range of variables against the same constant

I am currently attempting to find the bias for a range of means previously calculated against the same constant. I have been using the code
b_all<-bias(1,c(x2:x6))
But its only returning the bias of the first variable x2. I'm sure there is a simple fix that I'm just not seeing. Thanks for the help.
Hard to say without any data to verify, but this could work:
b_all <- sapply(2:6, function(i){bias(1,get(paste0("x", i)))})

Function definition from user input

I want to make a program where it will ask the user to enter a function, for example, cos(x) + 2. My problem is that, I do not know the syntax or the code on how to make the entered function become a real function where I can manipulate it, like get the derivative of it, plot it, something like that. Can anyone please teach me on how to do that? Thank you!
To create a "real" function, you can use 2 different syntaxes:
function [x]=myfct(a,b)
x=a+b;
endfunction
or
deff("[x]=myfct(a,b)","x=a+b");
Note: if you have only one return varaible, you can omit the square brackets.
The latter form is more straightforward here, because you only need to ask 2 or 3 strings from the user:
function_statement: the answer should be "x=a+b"
input_varaible_list (separated by comas): the answer should be "a,b"
output_varaible_list (separated by comas): the answer should be "x"
Then put it together in a deff:
deff("["+output_varaible_list+"]=myfct("+input_varaible_list+")",function_statement);
If you fix the output variable name as x, then you don't have to ask for it, and the user have to enter only the right hand side of the function statement (after the =). So it becomes:
deff("[x]=myfct("+input_varaible_list+")","x="+function_statement);
For the derivative see the derivative and numdiff functions in the Scilab help.

Jacop, constraint solver

I am a beginner in Jacop constraint solver. I looked into its documents but couldn't find how to solve my following problem. I have a matrix[n][n] of nxn domain variables of IntVar. Now, I need to apply the following constraint to it:
matrix[matrix[i][j]][k] == x
Here x is a regular integer, I mean not domain variable.
The problem that i am facing is that matrix[i][j] is a domain variable, and I am unable to give it as the first index in matrix[index][k] again.
I will really appreciate your help.
Basically you need to use element constraints to do that. First, create a vector matrix_k that represent a column k of matrix. Then, you can use Element constraint of the form Element(matrix[i][j], matrix_k, x).

Resources