I'm struggling on passing the column value to a formula. I tried many different combinations but I only have it working when I hard code the column,
(tbl as table, col as list) =>
let
avg = List.Average(col),
sdev = List.StandardDeviation(col)
in
Table.AddColumn(tbl, "newcolname" , each ([column] - avg)/sdev)
I'd like to replace [column] by a variable. In fact, it's the column I use for the average and the standard deviation.
Please any help.
Thank you
This probably does what you want, called as x= fctn(Source,"ColumnA")
Does the calculations using and upon ColumnA from Source table
(tbl as table, col as text) =>
let
avg = List.Average(Table.Column(tbl,col)),
sdev = List.StandardDeviation(Table.Column(tbl,col))
in Table.AddColumn(tbl, "newcolname" , each (Record.Field(_, col) - avg)/sdev)
Potentially you want this. Does the average and std on the list provided (which can come from any table) and does the subsequent calculations on the named column in the table passed over
called as x = fctn(Source,"ColumnNameInSource",SomeSource[SomeColumn])
(tbl as table, cname as text, col as list) =>
let
avg = List.Average(col),
sdev = List.StandardDeviation(col)
in Table.AddColumn(tbl, "newcolname" , each (Record.Field(_, cname) - avg)/sdev)
I need to read a specific column value of the last row of the below Variant table in SAP. When I record the script to navigate through the rows of the table, I get below lines. I need to extract specific cell value. Manually, I can copy and paste the content of the row to note pad. But, I am unable to figure out how to read the content of the specific column or entire row.
I have been trying different ways:
session.findById("wnd[0]/usr/subTABSTRIP:SAPLATAB:0100/tabsTABSTRIP100/tabpTAB06/" _
& "ssubSUBSC:SAPLATAB:0201/subAREA1:SAPLAIA1:0304/subSUB:SAPLAIA1:0308/" _
& "subTREE:SAPLAIA1:0306/cntlVARI_CANVAS/shell").selectedNode = "0001"
session.findById("wnd[0]/usr/subTABSTRIP:SAPLATAB:0100/tabsTABSTRIP100/tabpTAB06/" _
& "ssubSUBSC:SAPLATAB:0201/subAREA1:SAPLAIA1:0304/subSUB:SAPLAIA1:0308/" _
& "subTREE:SAPLAIA1:0306/cntlVARI_CANVAS/shell").selectedNode = "0002"
These are the lines generated when I move down the row using down arrow key. But how can I get the content of the row?
This is a GuiTree object, and more specifically one of type "Column Tree".
In your case, that will be:
set tree = session.findById("wnd[0]/usr/subTABSTRIP:SAPLATAB:0100/tabsTABSTRIP100/tabpTAB06/" _
& "ssubSUBSC:SAPLATAB:0201/subAREA1:SAPLAIA1:0304/subSUB:SAPLAIA1:0308/" _
& "subTREE:SAPLAIA1:0306/cntlVARI_CANVAS/shell")
The property SelectedNode gives a String which is the key of the node currently selected ("node" is for a line of the tree):
nodeKey = tree.SelectedNode
From there, you may access the node text with the method GetNodeText:
nodeText = tree.GetNodeText( nodekey )
The text of a cell is obtained with the method GetItemText ("item" being a cell at the intersection of a row and a column of the tree, excluding the left column containing the hierarchy):
itemText = tree.GetItemText( nodeKey, columnName )`
The column names are obtained with the method GetColumnNames:
set columnNames = tree.GetColumnNames()`
The column names being a GuiComponentCollection object, you loop at its elements as follows:
for i = 0 to columnNames.Length - 1
colunmName = columnNames.ElementAt(i)
next
I am trying to dynamically rename a set of columns in Power Query, List1 being the original column names and List2 the new column names. I think I need to merge List1 and List2 into a single list of pairs, but can't figure out the correct syntax.
Many thanks!
let
//list of original column names
List1= {"Name1","Name2","Name3","Name4"},
//Create test table
Source = Table.FromRows({{1231,1233,4121,5232},{3546,3426,1246,3464}} , List1),
//list of new column names
List2 = {"NewName 1","NewName 2","NewName 3","NewName 4"},
//Rename columns (in practice, the two lists of names will be dynamic, not hard coded as below)
Result = Table.RenameColumns(Source, {
{"Name1","NewName 1"},
{"Name2","NewName 2"},
{"Name3","NewName 3"},
{"Name4", "NewName 4"}})
in
Result
If you have a table with old and new names then you can use following pattern
let
rename_list = Table.ToColumns(Table.Transpose(Table2)),
result = Table.RenameColumns(Table1, rename_list, MissingField.Ignore)
in result
where Table2 is "Rename Table" and Table1 is initial table with data.
This idea is described in details here
https://bondarenkoivan.wordpress.com/2015/04/17/dynamic-table-headers-in-power-query-sap-bydesign-odata/
If you have the resulting column names you want, it seems like you could convert Source back to rows, then call Table.FromRows on List2
let
//list of original column names
List1= {"Name1","Name2","Name3","Name4"},
//Create test table
Source = Table.FromRows({{1231,1233,4121,5232},{3546,3426,1246,3464}} , List1),
//list of new column names
List2 = {"NewName 1","NewName 2","NewName 3","NewName 4"},
Result = Table.FromRows(Table.ToRows(Source), List2)
in
Result
(Unless it is wrong to assume that e.g. Name 2 will always be the second column.)
Stating the original problem according to Ivan's solution, here goes. Carl's has the same result and is a little simpler for the example I gave, however, my situation will benefit from having the rename pairs set out explicitly in a table (ie. Table2). Plus using the MissingField.Ignore parameter with Table.RenameColumns means that it will only change the selection of columns I want to rename in my production query, the rest will remain unchanged.
let
//list of original column names
List1= {"Name1","Name2","Name3","Name4"},
//Create test table
Source = Table.FromRows({{1231,1233,4121,5232},{3546,3426,1246,3464}} , List1),
//list of new column names
List2 = {"NewName 1","NewName 2","NewName 3","NewName 4"},
//Rename columns (in practice, the two lists of names will be dynamic, not hard coded as below)
//Bring List1 and List2 together as rows in a table
Table2 = Table.FromRows({List1,List2}),
//Create a list of rename pairs
RenameList = Table.ToColumns(Table2),
//Call to Table.RenameColumns
Result = Table.RenameColumns(Source, RenameList, MissingField.Ignore)
in
Result
Finally... figured it out using the following function
Table.TransformColumnNames(table as table, nameGenerator as function, optional options as nullable record) as table
First create a nameGenerator function (e.g. MyFuncRenameColumns) to provide a new column name given any original column name as an input.
In my example, here's my code for MyFuncRenameColumns:
let
MyFunctionSwitchColumnName = (originalColumnName) as text =>
let
//list of original column names
List1= {"Name1","Name2","Name3","Name4"},
//Create table
Source = Table.FromRows({{1231,1233,4121,5232},{3546,3426,1246,3464}} , List1),
//list of new column names
List2 = {"NewName 1","NewName 2","NewName 3","NewName 4"},
//Create table matching List1 to corresponding new value in List2
CreateRecord = Record.FromList(List2,List1),
ConvertedtoTable = Record.ToTable(CreateRecord),
//Filter table to just the row where the input originalColumnName matches
ReduceExcess = Table.SelectRows(ConvertedtoTable, each [Name] = originalColumnName),
//Return the matching result in the [Value] column (or give the original column name if there was no valid match)
NewColumnName = try ReduceExcess{0}[Value] otherwise originalColumnName
in
NewColumnName
in
MyFunctionSwitchColumnName
Here's where you use it as one of the parameters for Table.TransformColumnNames:
let
//list of original column names
List1= {"Name1","Name2","Name3","Name4"},
//Create table
Source = Table.FromRows({{1231,1233,4121,5232},{3546,3426,1246,3464}} , List1),
RenameColumns = Table.TransformColumnNames(Source, MyFuncRenameColumns)
in
RenameColumns
Hope that helps someone!
I'm new in Lotus Notes programming and I need your advices and your help.
My main form contains a table with 8 rows and 2 columns. ( there are 16 cells ) Every each cell has a numeric field. My fields name are :
txt_n1 and txt_i1 ( for 1st row )
txt_n2 and txt_i2 ( for 2nd row )
....
txt_n8 and txt_i8 ( for 8th row )
What I want to do is:
I have a view called vwMarketing with just one column. I want this view to display only those docs. in which there is at least one or more rows which its cells contains equal values.
So, if let say txt_n4 = txt_i4 => OK
row(k) (where k=1..8) : if cell 1 value is 5 and cell 2 value is 5 => OK.
There could be more than one row with this property, important is to exist at least one, and the values not to be null.
I hoped i was pretty clear, thanks !
PS: Actually, the formula statement i want to be in the column, so if it is OK => "A" and if not => "" ( in the view property, I checked : Don't show empty categories )
if you have small amount of documents in the view, then as u were suggested use Selection Formula to exclude documents with wrong condition.
you can add computed item/flag into your documents, field will compute if the document should be displayed in the view or not. then you will not have performance issue. i.e.
but code you need should look like that (that will check if documents is fine to be displayed in view or not), if you use it in view - just put after all Select _res = 1 otherwise if you decide to use flag into document (to increase performance) then Select youritem = 1
_res := 0;
#For(i:=1;i<=8;i:=i+1;
_post := #Text(i);
_txt_n := #GetField("txt_n"+_post);
_txt_i := #Text(#GetField("txt_i"+_post));
#If( (_txt_n=_txt_i) & (_txt_n!="");
#Do( _res := 1; i:=9);
0
)
);
_res
I would solve it slightly different:
Create a hidden text field on your form called 'DisplayInView' (or similar).
Modify the view selection: SELECT DisplayInView="Yes"
Add the code below to the PostSave event of your form:
Dim thisdoc As NotesDocument
Dim isSame As Boolean
isSame = False
Set thisdoc = source.Document
'*** Loop through all fields in document and compare the field pairs
Forall i In thisdoc.Items
If Left(i.Name,5) = "txt_n" Then
If i.Text = thisdoc.GetItemValue( Replace(i.Name,"txt_n","txt_i") )(0) Then
isSame = True
Exit Forall
End If
End If
End Forall
If isSame Then
Call doc.ReplaceItemValue("DisplayInView","Yes")
Call doc.Save(True,False)
End If
I haven't tested it, but I believe it should work.
i feeding my Data table from excel sheet upload,i face the problem when i look for a particular columns, ironically i don't know the position of column ,That can be anywhere or may be not present
so i cant Use indexing,when i go with column name then white spaces causing the problem
i assume the i know the index of Column but how can i handle the whitespaces
so far what i tried
Code:
if (ds.Tables[0].Columns[3].Caption.Replace(" ", "").Equals("XXXX"))
{
var ds = from r in ds.Tables[0].AsEnumerable() select new { Fname=r.Field<String>("XX XX") , Lname=r.Field<string>(" Yy YY Y ") };
ds.ToList();
}
Do i need to care About the case sensitiveness in Column Name ?
how can i find the Column index if it matched with a given String ?
You can find the column like:
DataColumn yourColumn = ds.Tables[0].Columns.Cast<DataColumn>()
.Where(r => r.Caption.Trim().Equals("XXXX",StringComparison.InvariantCultureIgnoreCase))
.FirstOrDefault();