Skip to content

Instantly share code, notes, and snippets.

@ralfbecher
Created May 1, 2017 20:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ralfbecher/cd7201296a669424f45d798a9d5e38e9 to your computer and use it in GitHub Desktop.
Save ralfbecher/cd7201296a669424f45d798a9d5e38e9 to your computer and use it in GitHub Desktop.
Qlik Script Sub KeepFields to Drop mass fields
Sub KeepFields(Fields,TableName)
Let n = NoOfFields('$(TableName)');
Set d = #;
For i = 1 to $(n)
Let f = FieldName($(i), '$(TableName)');
If Index('$(Fields)', ',$(f),') = 0 then
If '$(d)' = '#' then
Let d = '$(f)';
Else
Let d = '$(d),$(f)';
End if
End if
next
If '$(d)' <> '' then
Drop Fields $(d);
End if
End Sub
//Example:
//Call KeepFields(',CUSTOMER_ID,NAME,ADDRESS,PHONE,', 'Customer');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment