Link to home
Create AccountLog in
Avatar of michalek19
michalek19Flag for United States of America

asked on

Help to create script to calculate data from Google Sheet

Serverlist.xlsx

Open in new window

 Hi,

I need help to improve the” script” in Google Sheet to be able to 

1. Exclude from column “MANUFACTURER” : VMware, Azure and Aws. So, they are not included in the calculation cores in task 2 (below) 

2. Calculate how many cores were assigned to Physical and Virtual servers (Column INSTANCE TYPE) and define OPERATING SYSTEM names for each from (column OPERATING SYSTEM new).

3. Calculate cores total excluding VMware, Azure and Aws (Column MANUFACTURER)

 Or

If there is an easier way to get these information perhaps using Powershell or VB please assist.

Here is what I wrote for Google sheet. It works, but I am not getting the results I expected.

function myFilter() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var Serverlist = ss.getSheetByName("Servers");
  var dRng = Serverlist.getRange(2, 1, Serverlist.getLastRow(),44).getValues();
  var Criteria1 = Serverlist.getRange ("A31").getValue();
  var Criteria2 = Serverlist.getRange ("B31").getValue();
  var fData = dRng.filter(function(e){return (e)[3]== Criteria1 && e[32]==Criteria2});
  var newSht = ss.insertSheet();
  newSht.getRange(2, 1, fData.length, 44).setValues(fData);
  newSht.getRange ("AA:AA").setNumberFormat("0");
  var headers = Serverlist.getRange ("A1:AR1").getValues();
  newSht.getRange ("A1:AR1").setValues(headers);
}


What i need sample Output :

 

SERVER NAMEINSTANCE TYPEOPERATING SYSTEM (new)CORESTotal Core DatacenteTotal Core Standard
ABS2PhysicalMicrosoft Windows Server 2008 R2 Standard x6441223
ABS3PhysicalMicrosoft Windows Server 2008 R2 Standard x644

ABS4PhysicalMicrosoft Windows Server 2008 R2 Standard x64 Service Pack 11

ABS5PhysicalMicrosoft Windows Server 2012 R21

ABS6PhysicalMicrosoft Windows Server 2012 R2 Standard x641

ABS7PhysicalMicrosoft Windows Server 20161

ABS8PhysicalMicrosoft Windows Server 2016 (64-bit)2

ABS9PhysicalMicrosoft Windows Server 2016 Datacenter x642

ABS10PhysicalMicrosoft Windows Server 2016 Standard x642

ABS11PhysicalMicrosoft Windows Server 20192

ABS12PhysicalMicrosoft Windows Server 2019 Standard x642

ABS13PhysicalMicrosoft Windows Server 20228

ABS14VirtualMicrosoft Windows Server 2008 R2 Standard x648

ABS15VirtualMicrosoft Windows Server 2008 R2 Standard x642

ABS16VirtualMicrosoft Windows Server 2008 R2 Standard x64 Service Pack 11

ABS17VirtualMicrosoft Windows Server 2012 R22

ABS18VirtualMicrosoft Windows Server 2012 R2 Standard x644

ABS19VirtualMicrosoft Windows Server 20162

ABS20VirtualMicrosoft Windows Server 2016 (64-bit)4

ABS21VirtualMicrosoft Windows Server 2016 Datacenter x641

ABS22VirtualMicrosoft Windows Server 2016 Standard x641

ABS23VirtualMicrosoft Windows Server 20191

ABS24VirtualMicrosoft Windows Server 2019 Standard x643

ABS25VirtualMicrosoft Windows Server 20222

l


Thx, Michal

Avatar of Rob
Rob
Flag of Australia image

Any reason you couldn't just add another column with the formula: =IF(ISNA(MATCH(K2,{"VMware","Azure","AWS"},0)),AA2,0)


then just create a pivot table


Serverlist.xlsx

Avatar of michalek19

ASKER

Where i should insert this formula? should i add formula to the existing script?

I using Google Sheet. Where I should add this 


IF(ISNA(MATCH(K2,{"VMware","Azure","AWS"},0)),AA2,0)


This is what so far i have


unction myFilter() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var Serverlist = ss.getSheetByName("Servers");
  var dRng = Serverlist.getRange(2, 1, Serverlist.getLastRow(),44).getValues();
  var Criteria1 = Serverlist.getRange ("A31").getValue();
  var Criteria2 = Serverlist.getRange ("B31").getValue();
  var fData = dRng.filter(function(e){return (e)[3]== Criteria1 && e[32]==Criteria2});
  var newSht = ss.insertSheet();
  newSht.getRange(2, 1, fData.length, 44).setValues(fData);
  newSht.getRange ("AA:AA").setNumberFormat("0");
  var headers = Serverlist.getRange ("A1:AR1").getValues();
  newSht.getRange ("A1:AR1").setValues(headers);
}

no need for the script, unless i'm missing something.


Here it is as a google sheet: https://docs.google.com/spreadsheets/d/1SW06yJB1Q45dKDGl5c_8nBnhWBE3bexctMplTdcitJk/edit?usp=sharing

did you created a new filter?  is possible to show how many ms 2016 datacenter servers, ms 2012 standard servers, etc. and number of cors.

Have a look on the next tab "by Operating System"


can you also create by instance

take a look at that

How did you do that? have you used functions or script?

Can I copy your steps? if yes where i can find them?

I was able to recreated. 

How I can see total  cores in "by server?  Sheet must include  Host name, instance type, manufacturer, what MS OS is assigned to each server, Core numbers.   Can you exclude manufacturer AWS, AZURE, AWS? Can you exclude OS from the count like, RHEL, Ubundu, NetApp onTap


How I can see core total  in "by Operating Systems". I want to see only Microsoft product that is associated with Instance Type and Manufacturer (HPE , - , Rackspace ( column K -Manufacturer) . Can you exclude AWS, AZURE, AWS?


How I can see core total in "by instance". I want to see cores total for only physical and virtual instance. Can you exclude AWS, AZURE, AWS from the count?

Yes it's possible to do all that and just with pivot tables. You can add filters to the pivot to exclude things from the count.

In fact that's the easiest way and you can just have one pivot 

can you help me with that
ASKER CERTIFIED SOLUTION
Avatar of Rob
Rob
Flag of Australia image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer