HasField function

Applies To
Excel for Microsoft 365 Excel for Microsoft 365 for Mac Excel for the web

Use .HasField() to check whether a value has a field. It returns TRUE if the field exists and FALSE if it doesn't. For example, apply a discount only when an order has one.

.HasField() is a dot function: you call it on a value by typing a period after the value. For an overview, see Data types and dot functions in Excel.

Note

These features are rolling out to Microsoft 365 Insiders in Beta Channel on Windows Version 2612 (Build 20715.20000) or later and Mac Version 16.117 (Build 26111815) or later, and in Excel for the web.

Syntax

.HasField() returns TRUE if value has a field named field_name, and FALSE otherwise.

value.HasField(field_name)

Argument Description
value (required) The value before the dot: an entity (including a Linked Data Type such as Stocks), or a number, text, or Boolean that has fields. Can be a cell reference, a formula, or an array of values.
field_name (required) The name of the field to look for, as text, or an array of names.

Notes

  • Field names aren't case-sensitive, so .HasField("team") finds Team.
  • When field_name is an array, .HasField() returns one TRUE or FALSE for each name.
  • When value is a spilled array of entities, .HasField() returns one result for each entity, so you can use it with FILTER: =FILTER(D2#,D2#.HasField("Discount")).
  • For an entity whose fields were all removed, .HasField() returns FALSE.
  • Use .HasField() before reading a field that some values don't have. Reading a missing field returns the #FIELD! error.
  • To list the fields a value has, use .GetFieldNames().

Examples

Copy the example data and paste it in cell A1 of a new Excel worksheet. If you need to, you can adjust the column widths to see all the data.

Example 1

Check for fields, and fall back when one is missing.

Field Value
Name Ada
Team Design
Location London
Formula Result
=ENTITY(B2,A2:A4,B2:B4) Ada
=A6.HasField("Location") TRUE
=A6.HasField("Discount") FALSE
=IF(A6.HasField("Discount"),A6.Discount,0) 0

A6 uses the ENTITY function to build an employee entity: a value that shows Ada in its cell and holds Name, Team, and Location fields.

TRUE for the Location field, FALSE for a Discount field, and 0 from the fallback formula

Example 2

Check several names at once. Continuing from Example 1, enter this formula in D2:

Formula Result
=A6.HasField({"Team","Discount"}) TRUE, FALSE (spills into D2:E2)

Errors

Error Cause
#VALUE! value is a number, text, or Boolean with no fields.

See also