Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Want to see what's currently in public preview? We've pulled it all together in one place. Check it out here
cancel
Showing results for 
Search instead for 
Did you mean: 
hugmarcel
Specialist
Specialist

Automatically drop fields with 0 information density in script

Hi

I want to automatically drop all table fields in script, which have 0 Information density (= NULL values only). How can I achieve this?

Thx a lot!

Marcel

Labels (1)
11 Replies
hugmarcel
Specialist
Specialist
Author

Note that dropping a field in a table Impacts the internal field no index. Therefore you should use:

//Drop field with NULL values only, ignore fields in theExceptionFieldList

SUB DropQVFieldsWithNULLValuesOnly ( theExceptionFieldList )

  FOR a = 0 TO NoOfTables() - 1

    LET vTable = TableName($(a));

    LET d = 0;

    FOR i = 1 TO NoOfFields('$(vTable)')

        LET j = i - d;

        LET vField = FieldName($(j), '$(vTable)');

        LET vFieldValueCount = Alt(FieldValueCount('$(vField)'), 0);

        IF (vFieldValueCount <= 0 AND INDEX('$(vField)', '$(theExceptionFieldList)') <= 0) THEN

         DROP FIELD [$(vField)] FROM $(vTable);

         TRACE DROP FIELD [$(vField)] FROM $(vTable);

         LET d = d + 1; // dropping fields impacts the internal field no.

        END IF

       NEXT i

    NEXT a

END SUB

And call the SUB with e.g. CALL DropQVFieldsWithNULLValuesOnly ( 'Booking - not to be deleted' );

Marcel

jagan
Partner - Champion III
Partner - Champion III

Good catch Marcel.  I created a document in community with this content, because it may help others who are looking for similar one.

Link: Remove Empty columns (All Null values) in script dynamically

Regards,

Jagan.