Condition Based Result In another Column - javascript

I want to give condition in column B based on Column A data.
Example ColA have data Score i.e 80,90,40,50,60,70
and I want Column B should come If ColA=80 then "Good",90 then "Excellent",60 then Average
I am trying on it but output is not coming ok

Related

avoid - aggregation in ag-grid

i have ag-grid. This is the column structure -
account share qty
i'm grouping by account (rowGroup = true). I have this sample data -
account
share
qty
234
xny
4
234
ghy
3
this appears as
account
share
qty
234
0
xny
4
ghy
3
note that 0 comes for qty. this is because i havenot provided any aggregateFunction to colDef.
I want that qty cell to be empty for group level records (instead of showing a zero). is there a way to do it?
I'm not sure if this is the correct way but I was able to solve this by checking if the row is a group level row in my value formatter.
if the row is a group level row, i would return an empty string. otherwise, i would invoke the formatting function to show formatted data.

Google Sheets "Transpose(sort(transpose" -as Script

Is there a Google Sheets script that would be able to transpose my data, then sort it, then transpose it back. I need to do this formula below - but as a script.
=transpose(sort(transpose(J1:N4),1,))
My intention is to be able to sort my header columns A->Z so I can have a consistent placement of header columns every time I put them in. For example, sometimes the data comes as column A:G but the next time, the headers that used to be A:G are now AGBFCDE (scrambled). Sorting the entire columns going down is pretty strait forward but I need to sort A1:G1 while keeping the data below it still associated with the proper column header. For example, it would be "move entire column left or right" until the column headers are sorted A->Z. I am hoping this method of transposing-sorting-transposing back will do the trick but other recommendations would be welcome.
column 1 column4 column5 column 2 column 3
data 1 data 4 data 5 data 2 data 3
data 1 data 4 data 5 data 2 data 3
data 1 data 4 data 5 data 2 data 3
So as you can see above, the column headers are not in order. Every time I put them in, they will not be but I would like to know if there is preferably a script or some way to then sort Column 1:Column 5 in order even though they will never be pasted that way. If there is a better way besides transposing/sorting then I would be open to any method.
Here I created a script with the same concept of Transpose -> Sort -> Transpose.
function myFunction() {
// get all the data in the sheet
var ss = SpreadsheetApp.getActiveSheet();
var range = ss.getDataRange();
var values = range.getValues();
//convert rows into columns
var data = transpose(values);
//sort data
data.sort(
function(a,b) {
return b[0]-a[0] || a[0].localeCompare(b[0]);
});
//convert columns into rows
var data1 = transpose(data);
//write data back to spreadsheet
ss.getRange(1,1,values.length,values[0].length)
.setValues(data1);
}
function transpose(matrix) {
return matrix[0].map((col, i) => matrix.map(row => row[i]));
}
Example
Before
After
References
Transposing a 2D-array in JavaScript
JavaScript Sorting Arrays

Print For-Loop results in a table

I have 10 rows of data on my input step, i transform them in a for-loop and i should get more than 10 rows, but in this case i get the last transform of each iteration that the loop have for each data
I tried to use appendToFile() but the result data is not useful and pentaho read it as a unique header
On my alert() method i can see that the for loop transform the data.
var PERIODO = 2
var i
var fecha_final
//var ruta_acess ="D:\TEST.accdb"
//var contenido
////var contenido2
//var arreglo_completo
for (i=0; i<=PERIODO; i++){
fecha_final = dateAdd(FECHA_INICIO,"d",i)
Alert(i)
}
As I show in the below photo i get only 10 records and in the other photo appears the result that i want that are the results data of each iteration of the for-loop
Modified JavaScript value photo:
Expected result:
Obtained result:
For loops are not really a thing in PDI. Transformations work on sets of rows that flow through the steps, so it's best for performance and stability to use that mindset.
In your scenario each incoming row should end up as three copies, but with different calculated values based on a single new field (with values 0,1,2).
The way to do this in PDI is with a Join rows (cartesian product) step. It takes two sets of input rows and outputs a row for every combination of input rows, possibly filtered by defining a key field that has to match. So if you have 10 rows in the main input and 3 rows in the second, it will output 30 rows.
You will first need to create a data grid as the second input. Define a single integer field, name it something clear and on the second tab fill three rows with 0, 1 and 2 respectively.
Connect both inputs to the Join rows step. You don't need to configure any matching key.
The output of the Join step will be three rows for each input row, one with each of the values 0, 1, 2. Connect that output to a Calculator step and use the calculation Date A + B days to replace the logic from your javascript step.
what i mean is that in the obtained result photo the "i" variable only shows the value of "3" and i would like to have "1", "2" and "3"
to solve this i used
var row = createRowCopy(getOutputRowMeta().size())
var idx = getInputRowMeta().size()
row[idx++] = DPROCESS
this add a row for each result of the iteration.
before the tranformation result showed to me only the last value of each loop.

How do I get the column following a particular column?

I have a column and I'd like to get the column following that particular column.
nhood,column,variablecolumn
Treasure Island,3,5
McLaren Park,1,2
Tenderloin,28,112
Lakeshore,14,8
Chinatown,15,103
I know the name of the second column, but in my dataset the name of the third column changes.
I tried variants on this idea. I'm trying to get the number "5" from the first row.
parseFloat(data[1]["column"+1]);
parseFloat(data[1]["column"]+1);
Another idea is to create an array with the column names, pull the index for "column" and then use index + 1 when I pull the data in that particular command.
Got it. Like mentioned, you can turn the column names into an array and then pull the index for a particular array. In this case, you can use col as a stand-in for the variablecolumn name.
var valueKey = data.columns;
var col = valueKey[valueKey.indexOf(dataset)+1];

how to push key and value in array using Angular

I want to filter data on the basis of number of rows and columns provided by user.
I am getting the data on controller after reading this excel file:
this is the column header values which I am getting after user has passed 5 as input columns:
This is the row data which I am getting after user has given 4 rows as input to be rendered, here there is data of 4 rows:
Inside each row, there is key value pair containing column name and the cell value:
I want to filter this row data on the basis of the header names which are coming through column so that the row has only the values till the column is defined. Currently I am getting entire row values.
I have written a logic like this but this is not working.
var rowData=[];
for(var i=0;i<headerNames.length;i++){//headerNames contains column names
for(var j=0;j<data.length;j++){//data contains the rows data
for(var keyName in data[j])
if(angular.equals(keyName,headerNames[i])){
rowData.push({'keyName':data[j][keyName]})//I want only the key,values which matches the column names. I want to set the keyName value as array key but I am not getting its value instead it is coming like keyName:18
}
}
}
}
Adding the plunker for the code.
http://plnkr.co/edit/28Z44xDBug7nFCQnKZJL?p=preview
I am able to filter the data on UI and get only the row and column data as per user input.
But i need the same data on controller, so that i can save it in MongoDb. I want to filter the row data as per the column input. So, that i only get the row data till the column is defined.
Please suggest how can i filter the data and can splice the row values so that in row i can have value upto the column numbers defined. For eg, if I user have entered 4 rows and 5 columns then in my row Data i can have only values upto 5th column and all other values i can remove from array. in my code currently i am not able to get the key value to be set as array key.
Please help me to resolve this problem.
Looks like you're most of the way there. You just need to assign rowData to be $scope.rowData so that angular can get to it, and have the Angular document show {{rowdata}} (shows $scope.rowData).
You'll probably need to arrange it into columns though so you might do a ng-repeat on rowData, with variable=row, and in TR TD tags show row.1
eg something like ..
<tr ng-repeat="row in rowData">
<td>{{row.1}}</td>
<td>{{row.2}}</td>
</tr>

Categories