How do you create a "reverse pivot" in Google Sheets? -
I am trying to create a "reverse smoke" function. I've searched long and hard for this type of function, but can not find what is already out.
I have an abstract table anywhere from anywhere to 20 columns and hundreds of lines, although I would like to change it in a flat list so I used to create a database (or even flat for making more pivot tables) Data can be imported)
So, I have data in this format:
and it needs to be converted into this format Is:
I have created a function which is the limit from sheet 1 Haaga and again will add formatted lines have been down the same sheet, although I try to make it work, so I could get work on sheet 2, that sheet will read the entire range of 1.
Whichever I try, I can not do this to work, and wondering if anyone can give me any sign?
Even what I have so far:
function readRows () {var sheet = SpreadsheetApp .getActiveSheet (); Var rows = sheet.getDataRange (); Var numRows = rows.getNumRows (); Var values = rows.getValues (); For head = value [0] (var i = 1; i & lt; = numrows - 1; i ++) {for (var j = 1; j & lt; = value [0]. Length - 1; j ++) {var row = [value [i] [0], value [0] [j], value [i] [j]]; Sheet.appendRow (line)}}};
This is the basic array manipulation ... the code below is what you want
function transformData () {var sheet = SpreadsheetApp.getActiveSheet (); Var data = sheet.getDataRange (). GetValues (); // Read full sheet var output [=]; Var header = data.shift (); // headers empty = header. Shift (); // Remove empty cell on left var products = []; (Var d in data) {var p = data [de] .shift (); // Get the product name in the first column of the products in each line. Push (p); // store} logger.log ('headers =' + header); Logger.log ('products =' + product); Logger.log ('data only =' + data); (Var h in head) {for (var in products) {// iterative var row with two loops (header and product) = []; Row.push (header [hr]); Row.push (products [p]); Row.push (data [p] [h]) output push (line); // Collect data in different rows in the output array}} Logger.log ('output array =' output); Sheet.getRange (sheet.getLastRow) + 1,1, output.length, output [0] .length) .setValues (output); }
By typing the result in a new sheet automatically, replace the last line of code with:
var ns = spreadsheetApp.getActive (). GetSheets () Length + 1 SpreadsheetApp.getActiveSpreadsheet (). InsertSheet ('new sheet' + ns, ns) .Getreanz (1,1, output. Length, output [0]. Length) .Setwall (output);
Comments
Post a Comment