bradjasper / ImportJSON

Import JSON into Google Sheets, this library adds various ImportJSON functions to your spreadsheet

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

In Google Sheets Pivot Tables Calculated Fields formulas had problems

frafor opened this issue · comments

If !rawHeaders is set, then I modified this:

function defaultTransform_(data, row, column, options) {
      if (data[row][column] == null) {
        if (row < 2 || hasOption_(options, "noInherit")) {
          data[row][column] = "";
        } else {
          data[row][column] = data[row-1][column];
        }
      } 
    
      if (!hasOption_(options, "rawHeaders") && row == 0) {
        if (column == 0 && data[row].length > 1) {
          removeCommonPrefixes_(data, row);  
        }
        
        **data[row][column] = toTitleCase_(data[row][column].toString().replace(/[\/\_]/g, ""));**
      }
      
      if (!hasOption_(options, "noTruncate") && data[row][column]) {
        data[row][column] = data[row][column].toString().substr(0, 256);
      }
    
      if (hasOption_(options, "debugLocation")) {
        data[row][column] = "[" + row + "," + column + "]" + data[row][column];
      }
    }
    **data[row][column] = toTitleCase_(data[row][column].toString().replace(/[\/\_]/g, ""));**

It was .../g, " ", a space; it is now an EMPTY STRING.

When using the original data as the source of a Pivot Table, the Calculated Field formula would not work because of the SPACE at the beginning of all columns' names.

In the case of the column names of rawHeaders set, then I get all column names prefixed with '/', which make it impossible to use the column names in formulas for calculated fields.

I have not tried to fix the above so that the '/' prefix character is not included.

It would be nice to fix both things.

Thanks.