I have an Excel file where I want to group the columns based on multiple columns in C#. I am using EPPlus and have followed this link (Selecting grouped max and min in a Epplus worksheet with Linq), but it shows only the group by based on one column. I am stuck on extending it to group by multiple coulmns, let's say here Group and Date (Column A and Column B).
So, the following worked for me where I have grouped by based on first three columns of the Excel file:
var rowcellgroups = skus.Cells["A:G"].GroupBy(c => c.Start.Row);
var group = rowcellgroups.Skip(2).GroupBy(x => new { FirstKey = x.ElementAt(0).Value, SecondKey = x.ElementAt(1).Value, ThirdKey = x.ElementAt(2).Value }); //starts with 0
Related
I have a SharePoint list as a datasource in Power Query.
It has a "AttachmentFiles" column, that is a table, in that table i want the values from the column "ServerRelativeURL".
I want to split that column so each value in "ServerRelativeURL"gets its own column.
I can get the values if i use the expand table function, but it will split it into multiple rows, I want to keep it in one row.
I only want one row per unique ID.
Example:
I can live with a fixed number of columns as there are usually no more than 3 attachments per ID.
I'm thinking that I can add a custom column that refers to "AttachmentFiles ServerRelativeURL Value(1)" but I don't know how.
Can anybody help?
Try this code:
let
fn = (x)=> {x, #table({"ServerRelativeUrl"},List.FirstN(List.Zip({{"a".."z"}}), x*2))},
Source = #table({"id", "AttachmentFiles"},{fn(2),fn(3),fn(1)}),
replace = Table.ReplaceValue(Source,0,0,(a,b,c)=>a[ServerRelativeUrl],{"AttachmentFiles"}),
cols = List.Transform({1..List.Max(List.Transform(replace[AttachmentFiles], List.Count))}, each "url"&Text.From(_)),
split = Table.SplitColumn(replace, "AttachmentFiles", (x)=>List.Transform({0..List.Count(x)-1}, each x{_}), cols)
in
split
I manged to solve it myself.
I added 3 custom columns like this
CustomColumn1: [AttachmentFiles]{0}
CustomColumn2: [AttachmentFiles]{1}
CustomColumn3: [AttachmentFiles]{2}
And expanded them with only the "ServerRelativeURL" selected.
It would be nice to have a dynamic solution. But this will work fine for now.
I have data which users submit in columns. I am trying to convert them from columnar into stacked rows so a database can read them as single columns, rather than having to pull in X columns to capture the data.
You can see in the Columnar Example screenshot where I am presently, and in the Stacked Example where I want to be.
I can do this in either Google Sheets using App Script - load the data as columnar then convert to stacked and move to BigQuery - OR - use Google Cloud Storage to load the columnar data then use Node to convert to stacked when moving to BigQuery.
Either way, this needs to get into BigQuery as the Stacked Example.
Any ideas on how to do this?
The function below does the following:
Get all data from the sheet where your original data is located (called Source, please change accordingly) with getDataRange.
Remove the headers from the retrieved array and append them to your destination sheet (called Target) with shift, slice and appendRow.
Iterate through the rest of rows with a forEach and, for each row, iterate through each successive group of four columns with a for loop, appending (1) the first for columns of each row and (2) each successive group of four columns in a new row in your destination sheet.
function myFunction() {
var ss = SpreadsheetApp.getActive();
var sourceSheet = ss.getSheetByName('Source'); // Change accordingly
var targetSheet = ss.getSheetByName('Target'); // Change accordingly
targetSheet.clearContents(); // Removes all old content from target sheet before appending new data (remove this if you don't want that)
var sourceValues = sourceSheet.getDataRange().getValues();
var numCols = 4; // Number of desired columns in destination spreadsheet
var headers = sourceValues.shift().slice(0, numCols * 2);
targetSheet.appendRow(headers); // Remove if the destination sheet already has headers
sourceValues.forEach(function(row) { // Iterate through each row in source sheet
for (var i = numCols; i < row.length; i += numCols) { // Iterate through each group of four columns (excluding first four) in each row
var part1 = row.slice(0, numCols); // First four columns
var part2 = row.slice(i, i + numCols); // Each successive group of four
var targetRow = part1.concat(part2); // Concatenate the four first columns with each group of four
targetSheet.appendRow(targetRow); // Append row (8 columns)
}
});
}
Currently i am reading rows from the excel sheet and updating a SharePoint list. Some of them are look up columns.
Now say for example one row from excel is:
Distribution A+;#253;#Distribution FACTS;#256;#Distribution SX.e;#257
Now my requirement is i need to split them like:
ID;#Value;#ID;#Value;#ID;#Value
and then update in the list.
Code
if (string.IsNullOrEmpty(Convert.ToString(listTable.Rows[iRow][23]))) {
} else {
newlistitem["Product"] = Convert.ToString(listTable.Rows[iRow][23]);
}
I have an excel file which gets updated on a daily basis i.e the data is always different every time.
I am pulling the data from the Excel sheet into the table using Talend. I have a primary key Company_ID defined in the table.
The error I am facing is that the Excel sheet has few duplicate Company_ID values. It will also pick up more duplicate values in the future as the Excel file will be updated daily.
I want to choose the first record where the Company ID field is 1 and the record doesn't have null in the rest of the columns. Also, for a Company_ID of 3 there is a null value for one column which is ok since it is a unique record for that company_id.
How do I choose a unique row which has maximum no. of column values present ie for eg in the case of Company ID of 1 in Talend ?
tUniqRow is usually the easiest way to handle duplicates.
If you are worried that the first row coming to tUniqRow may not be the first row that you want there, you can sort your rows, so they enter tUniqRow in your preferred order:
(used components: tFileInputExcel, tJavaRow, tSortRow, tUniqRow, tFilterColumns)
In your particular case, the tJava could look like this:
// Code generated according to input schema and output schema
output_row.company_id = input_row.company_id;
output_row.name = input_row.name;
output_row.et_cetera = input_row.et_cetera;
// End of pre-generated code
int i = 0;
if (input_row.company_id == null) { i++; }
if (input_row.name == null) { i++; }
if (input_row.et_cetera == null) { i++; }
output_row.priority = i;
In the control properties, new row has name equals to Volume Row 62 and Row Index equals to 61 - as recorded and add values in few columns.
When I insert a new row with external data and fill the respective columns, it tries to override the column data in the row which was used in the recording and not the one that is being inserted.
If i remove the 62 and 61 from the Row Properties and make that general, it goes to the first row in the grid and tries to edit.
What properties should be changed or searched for so that columns is populated correctly in the the new row (whose name and row index is not known).
any help is appreciated.
Thanks.
To solve this in our application we exported the UI map method and created a temp list using VAR I don't know if this will work for you or not but solved several of our issues around dynamic grid rows and columns:
public void DoubleClickLaunch_UOW()
{
var temp = this.UIWindow.UIUnitGridTable.GetChildren().ToList();
temp.RemoveAt(0);
var rows = temp.Select(t => t.GetChildren().Select(s => s.GetValue()).ToList()).ToList();
var tractLetters = rows.Select(s => s[1]).ToList();
var index = tractLetters.IndexOf(DoubleClickLaunch_UOWParams.UITESTUNIT_TPText);
if (index >= 0)
{
var textbox = temp[index].GetChildren()[1].GetChildren()[0];
Mouse.DoubleClick(textbox);
}
else
{
Mouse.DoubleClick(this.UIWindow.UIUnitGridTable.UIItemRow.UIUnitNameCell.UITESTUNIT_TPText);
}