1 Reply Latest reply: Oct 16, 2015 1:01 AM by Evan Kurowski RSS

    Inconsistency in csv imports

    Lennaert van den Brink

      Hey all,

       

      Currently I have an issue with a .csv where the file is delivered to me with trailing spaces in header names. Apart from ways to deal with that issue, I find the behaviour of Qlikview a bit inconsistent. When importing a csv file headers are handled as follows:

       

      leading blank spaces are ignored (for example "    H1" becomes Load H1)

      trailing blank spaces are not ignored (for example "H2     " becomes Load [H2     ])

       

      I would be able to understand behaviour where either all leading and trailing spaces are trimmed or all are read into the header name, I would love to know the reasoning behind the current implementation.

       

      Can anyone enlighten me? Also, I could not find any documentation on this exact behaviour in the reference manual. Did I miss it or is it not described there?

        • Re: Inconsistency in csv imports
          Evan Kurowski

          Lennaert van den Brink wrote:

           

          Hey all,

           

          Currently I have an issue with a .csv where the file is delivered to me with trailing spaces in header names. Apart from ways to deal with that issue, I find the behaviour of Qlikview a bit inconsistent. When importing a csv file headers are handled as follows:

           

          leading blank spaces are ignored (for example "    H1" becomes Load H1)

          trailing blank spaces are not ignored (for example "H2     " becomes Load [H2     ])

           

          I would be able to understand behaviour where either all leading and trailing spaces are trimmed or all are read into the header name, I would love to know the reasoning behind the current implementation.

           

          Can anyone enlighten me? Also, I could not find any documentation on this exact behaviour in the reference manual. Did I miss it or is it not described there?

          Hello Lennaert,

          Not sure why the trim of whitespace in the fieldnames isn’t applied on both ends or even if it supposed to be, but I do have a suggestion that might let you use the field names as they are defined in the first row, spaces and all.

          Set verbatim = 1;

          //** make mapping table of field names from first row
          [MAP_AWKWARD_FIELDNAMES]:
          MAPPING LOAD '@' & Recno() AS FIELD, @1 AS ALIAS;
          LOAD @1 FROM [csv_example.txt]
          (
          txt, codepage is 1252, no labels, delimiter is ',', msq, filters (Transpose()));

          //** load data without labels
          [Data]:
          LOAD * FROM [csv_example.txt]
          (
          txt, codepage is 1252, no labels, delimiter is ',', msq) WHERE RecNo() > 1;

          //** reapply the verbatim field names
          RENAME FIELDS USING [MAP_AWKWARD_FIELDNAMES];