Access Query- how to get the maxium of several columns - ms-access

I have about 20 columns in a query and want to get the maximum amount in the last column. I tried the iif(a>b,a,iif(b>c,b,c)) but it doesn't work because a, b, c are not listed by any of orders.
Is there any formula I could use please?

You can use the following User-defined function (UDF):
Function Max(ParamArray a() As Variant) As Variant
Max = Empty ' return value in case of no supplied parameters
Dim i As Integer
For i = LBound(a) To UBound(a)
If i = LBound(a) Then
Max = a(i)
Else
If Max < a(i) Then Max = a(i)
End If
Next i
End Function
put it into your VBA module MyFnc (if it does not exist, create it) and use its result as
Max(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t)
what will satisfy your use of 20 columns.

Related

How to add days to today on a Google Query?

Using Google Query language, how do I properly add days to today?
I tried the below but if fails with an error.
SELECT A, B, C, D, E, F, H, I, K, M, N, R, AF, W WHERE
toDate(A) >= DATE '2021-12-16' and
toDate(A) <= DATE TEXT((TODAY()+15),"yyyy-mm-dd")
Error:
Google Sheets: Invalid query: PARSE_ERROR: Encountered " "toDate" "toDate "" at line 3, column 1. Was expecting: "(" ...
Try
=query( A:AF ,"SELECT A, B, C, D, E, F, H, I, K, M, N, R, AF, W WHERE
TODATE(A) >= DATE'2021-12-16' and
TODATE(A) <= DATE'"&TEXT((TODAY()+15),"yyyy-MM-dd")&"' ")

Trying to find index of minimum value in a list of vars in Octave

I have a list of vars with different values
a = 2
b = 1
c= 12343243
d = 8998
Can find the smallest value
aSmallestVALUE = min([a, b, c, d])
and index
[v,idx]=min([a, b, c, d])
I want to find the index of variable and sort this list from 0 to up
something like the
sorted list = b, a, d, c
Obviously if you want to treat those four variables as a 'list' to be sorted, you need to be working with a 'list' construct, not 4 isolated variables.
L = [2, 1, 12343243, 8998];
Otherwise it makes no sense to talk about the 'index' of an existing independent variable (though obviously you can construct this L from a bunch of pre-existing variables if desired).
With L in hand, you can now do
[minval, idx] = min( L )
% minval = 1
% idx = 2
to find the minimum and its corresponding index, and
[sorted, sortedindices] = sort( L )
% sorted =
% 1.0000e+00 2.0000e+00 8.9980e+03 1.2343e+07
%
% sortedindices =
% 2 1 4 3
to obtain a sorted array, with corresponding indices.

Function with vector as argument in Octave

How can I make a function with a vector as input and a matrix as an output?
I have to write a function that will convert cubic meters to liters and English gallons. The input should be a vector containing volume values ​​in m ^ 3 to be converted. The result should be a matrix in which the first column contains the result in m ^ 3, the second liter, the third English gallon.
I tried this:
function [liter, gallon] = function1 (x=[a, b, c, d]);
liter= a-10+d-c;
gallon= b+15+c;
endfunction
You're almost there.
The x=[a,b,c,d] part is superfluous, your argument should be just x.
function [liter, gallon] = function1 (x);
a = x(1); b = x(2); c = x(3); d = x(4);
liter = a - 10 + d - c;
gallon = b + 15 + c;
endfunction
If you want your code to be safe and guard against improper inputs, you can perform such checks manually inside the function, e.g.
assert( nargin < 1 || nargin > 4, "Wrong number of inputs supplied");
The syntax x=[a,b,c,d] does not apply to octave; this is reserved for setting up default arguments, in which case a, b, c, and d should be given specific values that you'd want as the defaults. if you had said something like x = [1,2,3,4], then this would be fine, and it would mean that if you called the function without an argument, it would set x up to this default value.

Google Script SetFormula escaping quotes

I cannot figure out the right combination of single and double quotes and \ to get this setFormula to work right.
SpreadsheetApp.getActiveSheet().getRange('F2').setFormula('=query(arrayformula(Master!A:K), "SELECT B, C, D, E, F, G, H, I, J, K where A = '"& 'Select Your Event'!A3 &"' Order By I, J",1)')
Use \' instead of ' on QUERY function literals inside the SQL argument
SpreadsheetApp.getActiveSheet().getRange('F2').setFormula('=query(arrayformula(Master!A:K), "SELECT B, C, D, E, F, G, H, I, J, K where A = \'"& \'Select Your Event\'!A3 &"\' Order By I, J",1)')

Return an array from a function and store it in the main program

Here is the Main Program:
PROGRAM integration
EXTERNAL funct
DOUBLE PRECISION funct, a , b, sum, h
INTEGER n, i
REAL s
PARAMETER (a = 0, b = 10, n = 200)
h = (b-a)/n
sum = 0.0
DO i = 1, n
sum = sum+funct(i*h+a)
END DO
sum = h*(sum-0.5*(funct(a)+funct(b)))
PRINT *,sum
CONTAINS
END
And below is the Function funct(x)
DOUBLE PRECISION FUNCTION funct(x)
IMPLICIT NONE
DOUBLE PRECISION x
INTEGER K
Do k = 1,10
funct = x ** 2 * k
End Do
PRINT *, 'Value of funct is', funct
RETURN
END
I would like the 'Sum' in the Main Program to print 10 different sums over 10 different values of k in Function funct(x).
I have tried the above program but it just compiles the last value of Funct() instead of 10 different values in sum.
Array results require an explicit interface. You would also need to adjust funct and sum to actually be arrays using the dimension statement. Using an explicit interface requires Fortran 90+ (thanks for the hints by #francescalus and #VladimirF) and is quite tedious:
PROGRAM integration
INTERFACE funct
FUNCTION funct(x) result(r)
IMPLICIT NONE
DOUBLE PRECISION r
DIMENSION r( 10 )
DOUBLE PRECISION x
END FUNCTION
END INTERFACE
DOUBLE PRECISION a , b, sum, h
DIMENSION sum( 10)
INTEGER n, i
PARAMETER (a = 0, b = 10, n = 200)
h = (b-a)/n
sum = 0.0
DO i = 1, n
sum = sum+funct(i*h+a)
END DO
sum = h*(sum-0.5*(funct(a)+funct(b)))
PRINT *,sum
END
FUNCTION funct(x)
IMPLICIT NONE
DOUBLE PRECISION funct
DIMENSION funct( 10)
DOUBLE PRECISION x
INTEGER K
Do k = 1,10
funct(k) = x ** 2 * k
End Do
PRINT *, 'Value of funct is', funct
RETURN
END
If you can, you should switch to a more modern Standard such as Fortran 90+, and use modules. These provide interfaces automatically, which makes the code much simpler.
Alternatively, you could take the loop over k out of the function, and perform the sum element-wise. This would be valid FORTRAN 77:
PROGRAM integration
c ...
DIMENSION sum( 10)
c ...
INTEGER K
c ...
DO i = 1, n
Do k = 1,10
sum(k)= sum(k)+funct(i*h+a, k)
End Do
END DO
c ...
Notice that I pass k to the function. It needs to be adjusted accordingly:
DOUBLE PRECISION FUNCTION funct(x,k)
IMPLICIT NONE
DOUBLE PRECISION x
INTEGER K
funct = x ** 2 * k
PRINT *, 'Value of funct is', funct
RETURN
END
This version just returns a scalar and fills the array in the main program.
Apart from that I'm not sure it is wise to use a variable called sum. There is an intrinsic function with the same name. This could lead to some confusion...