Record.HasFields Function in Power Query

The Record.HasFields function returns true if the field name or field names are present in a record, otherwise false.

Note: Multiple field names can be specified using a list. If multiple field names are specified, then all fields listed must be present in the record only then it returns true otherwise false.

Syntax

Record.HasFields(record as record, fields as any) as logical

Example: Check the record has the Name field.

Power Query M

let
  MyTable = Table.FromRecords(
    {
      [CustomerID = 1, Name = "Ashish", Phone = "123-4567"], 
      [CustomerID = 2, Name = "Katrina", Phone = "987-6543"], 
      [CustomerID = 3, Name = "Alia", Phone = "543-7890"], 
      [CustomerID = 4, Name = "Vicky", Phone = "676-8479"], 
      [CustomerID = 5, Name = "Mohini", Phone = "574-8864"], 
      [CustomerID = 6, Name = "Meenakshi", Phone = "574-8864"], 
      [CustomerID = 7, Name = "Esha", Phone = "574-8864"], 
      [CustomerID = 8, Name = "Anjali", Phone = "574-8864"]
    }
  ),

Return = Record.HasFields(MyTable{0},"Name")
//Here, by using the {0} we are extracting the first record from the table as record

in
    Return 

The output of the above code will be true as the Name column is available in the record.

Example: Check the record has the Name and Salary fields.

Power Query M

let
  MyTable = Table.FromRecords(
    {
      [CustomerID = 1, Name = "Ashish", Phone = "123-4567"], 
      [CustomerID = 2, Name = "Katrina", Phone = "987-6543"], 
      [CustomerID = 3, Name = "Alia", Phone = "543-7890"], 
      [CustomerID = 4, Name = "Vicky", Phone = "676-8479"], 
      [CustomerID = 5, Name = "Mohini", Phone = "574-8864"], 
      [CustomerID = 6, Name = "Meenakshi", Phone = "574-8864"], 
      [CustomerID = 7, Name = "Esha", Phone = "574-8864"], 
      [CustomerID = 8, Name = "Anjali", Phone = "574-8864"]
    }
  ),

Return = Record.HasFields(MyTable{0},{"Name", "Salary"})
//Here, by using the {0} we are extracting the first record from the table as record

in
    Return  

The output of the above code will be false as the Name column is available in the record, but Salary column is not available in the record. And if multiple field names are given in the function as the second argument then all should be in the record to return true.