Value property

NamedValue.Value

Special value available in formulas:

Item

NamedValue

The named value this property is part of, enabling multiple checked items in the app designer to share the same formula and be updated all at once.

Consider the fields Field1 and Field2, which should only be considered to be valid if their values are greater than 4. Without using the Item value, the Valid property of Field1 would need to use the formula Field1 > 4Field1 > 4 and the Valid property of Field2 would need to use the formula Field2 > 4Field2 > 4.

Using Item, both formulas can read Item > 4Item > 4. This is useful if you have many fields and you want to be able to update their formulas all at once. To do so, click their check boxes in Calcapp Creator and make sure that a checked field is selected. Then, when you update a formula for one checked field, you update all the other checked fields too, which is a great timesaver.

Use Item in exactly the same way you'd use the regular name. NamedValue1.VisibleNamedValue1,Visible and Item.VisibleItem,Visible are equivalent, for instance.

The value, which can represent anything a formula can return.

Named values can be used to cut down on repetition in formulas, enabling multiple formulas to use the same values. If several formulas include identical fragments, it is often better to break out these fragments into named values. That way, the original formulas become shorter and easier to read, and also run faster.

Named values also lessen the risk of errors creeping in, as formula fragments, that were previously repeated throughout several formulas, only have to be updated in one place.

In order to name values which are only accessible from a single formula, use the LET function instead.

Named values versus hidden fields

Hidden fields can also be used to realize many of the same benefits. While named values are more lightweight than hidden fields, the key difference is that fields can only represent numbers, logical values (TRUE or FALSE) and text strings, whereas named values can represent anything a formula can return.

Consider an app with a large number of formulas that all need to determine which field to reference. Perhaps the choice depends on the current month:

IF(MONTH(TODAY()) = 3, MarchResultField, ResultField)IF(MONTH(TODAY()) = 3; MarchResultField; ResultField)

Let's assume that the formula above is assigned to this property, of a named value named RelevantResultField. Other formulas can then reference the named value and treat it as though it were a field:

ALERT("The result is " & RelevantResultField.FormattedValue & ".")ALERT("The result is " & RelevantResultField,FormattedValue & ".")

Hidden fields can only reference numbers, logical values and text strings, and as a result can't be used to realize this scenario.

There is one area where hidden fields work better than named values, though: only fields work with :=, which assigns values to properties from action formulas. If you need to store a value for later use from an action formula, use a field and not a named value.

Named values representing arrays

The most common use of named values is probably to represent arrays. An array can be likened to an ordered list of values, and is written as follows:

{ 10, 20, 30, 40, 50 }{ 10; 20; 30; 40; 50 }

Let's assume that the formula above is assigned to this property, of a named value named NumberSequence. It can be treated as an ordinary array, meaning that these formulas are equivalent and both return 20 (because the INDEX function is instructed to return the second element):

INDEX({ 10, 20, 30, 40, 50 }, 2)INDEX({ 10; 20; 30; 40; 50 }; 2)
INDEX(NumberSequence, 2)INDEX(NumberSequence; 2)

Named values can represent columns in a table of data. This enables functions like XLOOKUP, XMATCH, AVERAGE, COUNT, COUNTIF, MAX, SUM, SUMIFS and FILTER to process the data.

Calcapp Creator provides a convenient spreadsheet-like data editor that allows you to edit named values holding array data.

Example formulas processing employee data

Consider a screen named Employees, which holds two named values: Name and Salary. The first holds an array of text strings, representing the names of employees working at a fictitious company, and the latter holds an array of numbers, representing their salaries.

This formula looks up the salary of an employee, whose name is stored in NameField:

XLOOKUP(NameField, Employees!Name, Employees!Salary)XLOOKUP(NameField; Employees!Name; Employees!Salary)

This formula returns the average salary:

AVERAGE(Employees!Salary)AVERAGE(Employees!Salary)

This formula returns the number of employees who earn more than $50,000 per year:

COUNTIF(Employees!Salary, ">50000")COUNTIF(Employees!Salary; ">50000")

Finally, this formula looks up the name of the employee with the highest salary:

INDEX(Employees!Name, XMATCH(MAX(Employees!Salary), Employees!Salary))INDEX(Employees!Name; XMATCH(MAX(Employees!Salary); Employees!Salary))

Examples

IF(Field1 = 2, OneField, AnotherField)IF(Field1 = 2; OneField; AnotherField)

Returns OneField if the value of Field1 equals 2. Otherwise, AnotherField is returned. Named values can represent anything a formula can return.

IF(SettingsScreen!DarkTheme, Color.Black, Color.White)IF(SettingsScreen!DarkTheme; Color,Black; Color,White)

Returns the color black if the switch field DarkTheme is toggled to its "on" position. Otherwise, the color white is returned. A set of colors can be maintained as named values, which represent the colors of a theme. If the user is able to select their preference using a settings screen, these named values can be referenced from properties such as BackgroundColor of screens.

IF(SettingsScreen!PreferredDateFormat = "Short", DateFormat.Numeric, DateFormat.Full)IF(SettingsScreen!PreferredDateFormat = "Short"; DateFormat,Numeric; DateFormat,Full)

Returns DateFormat.NumericDateFormat,Numeric if the text drop-down field PreferredDateFormat equals "Short". Otherwise, DateFormat.FullDateFormat,Full is returned. The user's preferred date format can be maintained as a named value, holding a DateFormat value, which can be passed directly to the FORMATDATE function.

XLOOKUP(NameField, Employees!Name, Employees!Salary)XLOOKUP(NameField; Employees!Name; Employees!Salary)

Returns the salary of an employee, whose name is stored in NameField. Name and Salary are named values holding an array of text strings and an array of numbers, respectively.

AVERAGE(Employees!Salary)AVERAGE(Employees!Salary)

Returns the average salary. Salary is a named value holding an array of numbers.

COUNTIF(Employees!Salary, ">50000")COUNTIF(Employees!Salary; ">50000")

Returns the number of employees who earn more than $50,000 per year. Salary is a named value holding an array of numbers.

INDEX(Employees!Name, XMATCH(MAX(Employees!Salary), Employees!Salary))INDEX(Employees!Name; XMATCH(MAX(Employees!Salary); Employees!Salary))

Returns the name of the employee with the highest salary. Name and Salary are named values holding an array of text strings and an array of numbers, respectively.