//Subroutine for fields to filter on //Creates a WHERE statement which can be used in table loads to restrict the data to a smaller set //This WHERE statement is for loading from a QVD. To load from SQL db change to 'WHERE IN()' SUB ExtendWhere(Name, ValVarName) //Name will be the filtered field name and ValVarName the values LET T = Name & '_COLNAME'; LET ColName = $(T); LET Values = $(ValVarName); IF len(Values) > 0 THEN IF len(WHERE_PART) > 0 THEN //If WHERE clause exists then extend it with further values LET WHERE_PART = '$(WHERE_PART) AND MATCH($(ColName),$(Values))'; ELSE LET WHERE_PART = ' WHERE MATCH($(ColName),$(Values))'; //If WHERE clause does not exist then create it ENDIF ENDIF END SUB; //Here we set the variables ready to hold the names of any fields we want considering for ODAG filtering (selection) //The ods_ field names bind the fields to those in your Selections Application. //The two Sel_ variables below are examples. Replace Customer and Sub_Group with your own fields. SET Sel_Customer = ; //resets the variable from any previous reload SET Sel_Customer = $(ods_Customer_Name); // follow 'ods_' with the field name as it appears in your UI / final load SET Sel_Customer_COLNAME ='CUST_NAME'; // enter the field name as it appears in the source data (e.g. QVD/SQL db) SET Sel_Sub_Group = ; SET Sel_Sub_Group = $(ods_Sub_Group_Name); SET Sel_Sub_Group_COLNAME ='SUBGROUP_NAME'; SET WHERE_PART = ''; //you may opt to add your own WHERE clause that is used in every ODAG //e.g. you always want 2018 data... 'WHERE Year = 2018' //if so the sub routine will extend it with further selections //This section builds the WHERE_PART variables that are passed to the SUB //It extracts the values that have been selected from each field FOR EACH fldname IN 'Sel_Customer', 'Sel_Sub_Group' //insert your Sel_ variables LET vallist = $(fldname); WHEN (IsNull(vallist)) LET vallist = ''; //If Qlik suggests an error here ignore it IF len(vallist) > 0 THEN CALL ExtendWhere('$(fldname)','$(vallist)'); ENDIF NEXT fldname //Evaluate the WHERE_PART variable in the script for debugging TRACE Generated WHERE clause: ; TRACE $(WHERE_PART);