Saturday, August 10, 2013

Google Spreadsheet Transpose Values after Searching Multiple Columns

Question:

( by rajvivek )


Hi!

In order to get some result through filter and transpose, i am using this formula in a single cell : =transpose(filter(A$2:A$100, B$2:B$100=D2, C$2:C$100=E2))

How to edit the above formula so that it could automatically populate the data down the G column.

I have tried to add ArrayFormula and MMULT in various combination but none of them are working.

Thanks!

Solution:

Following is the solution using script..

Have a look at the following screenshot:



I have the following formula in Cell G2:
=ksearch(A2:C;D2:E)

the above formula is a custom function ksearch() that I have written and inserted in Script.

Have a look at the following code:

///////////////////////////////////////

//search(Data,searchArray)

function ksearch() {
  if(arguments.length < 2 || arguments.length > 2) return "Please input 3 arguments";
  
  var data = arguments[0];
  var searchArray = arguments[1];
  var returnArray = new Array();
  
  for(var i=0;i<searchArray.length;i++) {
    returnArray[i] = new Array();
    for(var j=0;j<data.length;j++) {
      if(data[j][0]!='' && searchArray[i][0]==data[j][1] && searchArray[i][1]==data[j][2])
        returnArray[i].push([data[j][0]]); // 0 because we want to return Column 1 of Data.
    }    
  }
  return returnArray;
}

///////////////////////////////////////

put the above code in your script editor, and then you can use it directly in your Google Spreadsheet or you can use its functionality in the Google Apps Script.



And If you are not much familiar with scripts then check out the following link:
http://igoogledrive.blogspot.com/2012/08/how-to-write-script-in-google.html 

I hope the above solution will help you, and if you need more help then please do comment below on this blog itself, I will try to help you out.


I also take up private and confidential projects:
If this blog post was helpful to you, and if you think you want to help me too and make my this blog survive then please donate here: http://igoogledrive.blogspot.com/2012/09/donate.html 

Thanks,

No comments:

Post a Comment