Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago

Speed up a List.Contains process

let
Source = Excel.Workbook(File.Contents("abc.xlsx"), null, true),
FTEDATA_DefinedName = Source{[Item="FTEDATA",Kind="DefinedName"]}[Data],
#"Promoted Headers" = Table.PromoteHeaders(FTEDATA_DefinedName, [PromoteAllScalars=true]),
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"EMPNO", type text}, {"REPORTING_OFFICER_ID", type text}}),

#"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if List.Contains(Table.Column(#"Changed Type","EMPNO"),[REPORTING_OFFICER_ID]) then 1 else 0)
in
#"Added Custom"

 

I am using the above code to lookup REPORTING_OFFICER_ID in EMPNO (both in same table) and create a new column to show if there's a match or not.

 

The problem is that the code runs super slow taking several minutes to produce the new column. Any ideas on how to speed things up?

 

1 Reply

  • Anonymous , try like this

    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if List.Contains(#"Changed Type"[EMPNO],[REPORTING_OFFICER_ID]) then 1 else 0)