Excel PowerQuery: how do I add an IsNotNull column - powerquery

I have a simple function that I'd like to run on the values in a column, resulting in another column.
let
ThisIsNotNull = (input) => if (input = null) then false else true,
Source = ...
eventually there is a text column with Nulls in it, let's call it TextColumn.
I'd like to add another column alongside it with a value of =ThisIsNotNull(TextColumn).

Add column... Custom column with formula
= ThisIsNotNull([NameOfColumnToTest])
But really you can skip the function and just use
= if [NameOfColumnToTest] = null then false else true

Related

Check if query is empty is null before rest of query steps

Good morning everyone,
I'm trying to edit a query that takes a worksheet from an Excel file (as a parameter), then conditions this for other query steps that include appending further down the query chain.
However, in some excel files, this worksheet is effectively blank, containing only:
Column1
null
null
I want to create a step in the query that checks whether the excel worksheet is like the above, and then create columns (Field_code, and Dev_status) in the same format as other queries so that it does not break the append step.
Any help would be greatly appreciated!
Full code from the advanced editor below:
let
FilePath1 = Excel.CurrentWorkbook(){[Name="FilePath1"]}[Content]{0}[Column1],
Source = Excel.Workbook(File.Contents(FilePath1), null, true),
#"Technical(Oil)1" = Source{[Name="Technical(Oil)"]}[Data]
in
#"Technical(Oil)1"
Add two new steps; first declare the transformations you want to do if the table is Empty (WhenNull) then use if statement which test to see if your table is empty with (Table.IsEmpty(#"Technical(Oil)1")) if true then return your new step otherwise return the table.
let
FilePath1 = Excel.CurrentWorkbook(){[Name="FilePath1"]}[Content]{0}[Column1],
Source = Excel.Workbook(File.Contents(FilePath1), null, true),
#"Technical(Oil)1" = Source{[Name="Technical(Oil)"]}[Data],
WhenNull = Table.AddColumn(
Table.AddColumn(#"Technical(Oil)1","Field_code", each null)
,"Dev_status", each null),
Result = if Table.IsEmpty(#"Technical(Oil)1") then WhenNull else #"Technical(Oil)1"
in
Result

Count number of rows based on filter JQGrid

JQ grid having column name mobile
I have jq grid which has column 'Mobile Login',It contains values 'Yes' and 'No' only.
My requirement is to get count of 'Yes' value and show in footer.
Currently i am using below code in load complete event of JQ Grid
grid.jqGrid("getCol", colName, false, "count")
Is their any way to add condition where value = 'Yes' in jqgrid.
There are many ways to do this, but it is needed to have more information on your jqGrid configuration - like datatype, loadonce and etc.
To solve the problemin based on your information, you can just use the getCol, but to return array from object values and then looping this array can give you the needed result.
var colvals = grid.jqGrid("getCol", colName, true),
len = colvals.length,
i=0,
yescounter=0;
while(i<len) {
if(colvals[i].value === 'Yes') {
yescounter++;
}
i++;
}
Hope this helps

Talend: Save variable for later use

I´m trying to save a value in spreadsheet's header for later use as a new column value.
This is the reduced version with value (XYZ) in header:
The value in header must be used for new column CODE:
This is my design:
tFilterRow_1 is used to reject rows without values in A, B, C columns.
There is a conditional in tJavaRow_1 to set a global variable:
if(String.valueOf(row1.col_a).equals("CODE:")){
globalMap.putIfAbsent("code", row1.col_b);
}
The Var expression in tMap_1 to get the global variable is:
(String)globalMap.get("code")
The Var "code" is mapped to column "code" but I'm getting this output:
a1|b1|c1|
a2|b2|c2|
a3|b3|c3|
What is missed or there is a better approach to accomplish this escenario ?
Thanks in advance.
Short answer:
I tJavaRow use the input_row or the actual rowN in this case row4.
Longer answer, how I'd do it.
I'd do is let the excel flow in AS-IS. By using some Java tricks we can simply skip the first few rows then let the rest of the flow go through.
So the filter + tjavarow combo can be replaced with a tJavaFlex.
tJavaFlex I'd do:
begin:
boolean contentFound = false;
main
if(input_row.col1 != null && input_row.col1.equalsIgnoreCase("Code:") ) {
globalMap.put("code",input_row.col2);
}
if(input_row.col1 != null && input_row.col1.equalsIgnoreCase("Column A:") ) {
contentFound = true;
} else {
if(false == contentFound) continue;
}
This way you'll simply skip the first few records (i.e header) and only care about the actual data.

How to remove or hide the data value not required from table in birt tool

How do I remove or hide the data value not required from table in birt tool?
I tried with the values it works in some places but now in groups which has multiple values.
I need to filter some of the values which should not be displayed in the data tab of the table.
I have a column which does not have any value that I need to filter out (But its not an empty value because when I check I got to know that it has some blank spaces). It should display only the columns with non-blank value.
How can I remove those columns from the data set.
You can of course try scripting the data source query but you can also run a script on the table when it is created to hide the empty column.
Try this script in the table's onCreate event:
var mycolumnCount = this.getRowData().getColumnCount();
var DisNull = false;
for(i=1;i<mycolumnCount;i++) {
var temp = this.getRowData().getColumnValue(i)
if(this.getRowData().getColumnValue(i) == "") {
DisNull = true;
}else{
DisNull = false;
i = mycolumnCount+1;
}
}
if(DisNull == true) {
this.getStyle().display = "none"
}

Bind Objects To DataGridview and Reorder Column

I want to bind the object list to dataGridView.
Now i want the desired column to be the way i definde them. i.e., I want the objects to be order the way i want.
Like
var dataSource = linkItemListCommon.Select(x => new DataToBind { Select = x.Default, FileName = x.Text, CurrentDate = x.Date+" "+x.Time , PreviousDate = string.Empty, Size = x.Size }).ToList();
var filenamesList = new BindingList<DataToBind>(dataSource);
dgvDownLoadMaster.DataSource = filenamesList;
I want the datagrid columns to be in the order that i define.
Like here i expect them to be in order given below:
Select FileName CurrentDate PreviousDate Size
But the column list is appearing not as per my requirements.
How to Do that.Please help.
Create columns by hand and then you can order them easily. You can add columns trough designer and just set each column DataPropertyName to corresponding field.
Or you can create each column programmatically:
var col = new DataGridViewTextBoxColumn();
col.DataPropertyName = "Select ";
col.HeaderText = "Select";
col.Name = "ColSelect";
dgvDownLoadMaster.Columns.Add(col);
you have to do this for each column and do it before databinding.

Resources