<< Get Values is used to get the values from column into a list or matrix (depends on data type).
Loc() can be used to get the indices from the matrix/list which match the item we provide it with OR return indices of non-missing values (very good function to know in my opinion).
Loc will return a matrix, so we use N Items() to check if there are any indices found to avoid issues when accessing the indices. If no index is found we set value for those rows as missing ".".
Based on the data provided, I chose to always use first index from the indices. It is possible to use all of them if more complicated calculations were needed in case of multiple matches.
Below is the formula creation with some comments
Names Default To Here(1);
dt = New Table("Calculated concentration - Dummy table",
Add Rows(6),
Compress File When Saved(1),
New Column("Given Concentration", Numeric, "Continuous", Format("Best", 12), Set Property("Units", "ppm"), Set Values([12, 50, 23, 14, 2, .])),
New Column("Letters", Character(1), "Nominal", Set Values({"A", "B", "C", "D", "E", "F"}), Set Display Width(38)),
New Column("Used solution for dilution", Character, "Nominal", Set Values({"", "", "", "", "", "C"})),
New Column("Dilution Factor", Numeric, "Continuous", Format("Best", 12), Set Values([., ., ., ., ., 2.29837984]))
);
dt << New Column("Calculated Concentration (ppm)", Numeric, Continuous, Formula(
// use As Constant to evaluate this only once (should make it more efficient if you have lots of data)
As Constant(all_letters = :Letters << get values); // << get values gets values from column into a matrix or list
idx_for_letter = Loc(all_letters, :Used solution for dilution); // Loc can be used to return indices of matches in matrix but it has many other uses
If(N Items(idx_for_letter) == 0, // to avoid issues when trying to access incorrect indices, check for empty matrix
. // set missing value to column IF no indices found
,
:Given Concentration[idx_for_letter[1]] / :Dilution Factor // perform calculation using first index found from idx_for_letter
);
));
To get explanation about used functions I would suggest first using Scripting Index to search for the function and then clicking "Topic Help" to get to help page. For example search for "as constant"
and click topic help to open this page As Constant(expr)
-Jarmo