Libreoffice Calc / Excel - Multiple IF statments - libreoffice

I'm at a loss here, I'm just wanting to match the contents of a cell to a partial value and if true, set the value in a new cell.
Colum E2 contents (2 rows):
MCDONALD'S #49019 QF5
THRIFTY FOODS #5649 NEW YORK
In cell E3 for example I have this:
=IF(ISERR(SEARCH("*MCDONALD'S*", E2)), "no match", "fast food"),
IF(ISERR(SEARCH("*THRIFTY FOODS*", E2)), "no match", "grocery")
It results in an error.
Now if I just have the first condition:
=IF(ISERR(SEARCH("*MCDONALD'S*", E2)), "no match", "fast food")
Then is works just fine, so how do I get this to work with multiple conditions?
Also trying this, with no success. It successfully matches the first criteria, but when the second criteria matches I just get the "Error" value...
=IFERROR( IF(SEARCH("MCDONALD'S", E3),"Fast Food", IF(SEARCH("THRIFTY", E3),"Grocery", "No Match" ) ) ,"Error")

Related

Mongoid query with AND and OR condition

I am using a MongoDB for a new app I am creating and I only need certain data from it. I require the following fields: current (boolean), position, sector, and name. The position field is populated with one of four values - "cash, SPVR, OFF, and training", while the sector field has one of two values - "Break or Working". I want a query that will give me all records where the following conditions exist:
1. current = TRUE
2. Position = "SPVR" or "CASH" OR Sector = "BREAK" and
3. Name is not NULL
The problem I have is that there are hundreds of records that have a value of BREAK, but most of them do not have a value in the Name field. I don't want any records that do not have a name associated with them. So in that respect, in line 2 above, I'm guessing the OR could be AND?
This is mu current start at the Mongoid statement
get '/currentstate*' do
StateTransaction.where( current: true, :position.in =>["SPVR", "CASH"] ).to_json
end
Any help would be greatly appreciated.
Thanks!!
It should work
StateTransaction.where(current: true, :name.ne => ["",nil]).and(
StateTransaction.or(
{:position.in =>["SPVR", "CASH"]},
{sector: "BREAK"}
).selector
)
Following is arguably simpler:
sts = StateTransaction.where(current: true, :name.ne => ["",nil])
sts.any_of(:position.in => ["SPVR", "CASH"], sector: 'BREAK')

SSRS Expression inversed return

So I have an expression that calculates the number of weekdays between two dates (excluding these dates). But the expression seems to give the opposite results of what I want and I don't know why. Here's the expression:
=iif(IsNothing(Fields!End_Date.Value) or IsNothing(Fields!Report_Submitted_Date.Value) or Fields!Report_Submitted_Date.Value>Fields!End_Date.Value,"Invalid Data",
(DateDiff(DateInterval.day,Fields!End_Date.Value,Fields!Report_Submitted_Date.Value)+1)
- (DateDiff(DateInterval.WeekOfYear,Fields!End_Date.Value,Fields!Report_Submitted_Date.Value)*2)
- IIF(Weekday(Fields!End_Date.Value,1) = 1,1,0)
- IIF(Weekday(Fields!End_Date.Value,1) = 7,1,0)
- IIF(Weekday(Fields!Report_Submitted_Date.Value,1) = 1,1,0)
- IIF(Weekday(Fields!Report_Submitted_Date.Value,1) = 7,1,0)-2)
So, the result I get from this expression is that every situation where the End Date is smaller than the Report Submitted Date I get the text Invalid Data and the rest are #Error or negative numbers.
Now I know I can solve this by switching the True and False clause but I would like to understand why these results are switched because for as far as I can read:
IF End Date OR Report Submitted Date are null
OR IF End Date is bigger than Report Submitted Date I should get the Invalid Data text.
Any answers are appreciated.
EDIT 1:
So I have changed the expression from an IIF to a switch.
=switch(
IsNothing(Fields!End_Date.Value),"Invalid Data",
IsNothing(Fields!Report_Submitted_Date.Value),"Invalid Data",
Fields!Report_Submitted_Date.Value <= Fields!End_Date.Value, "Invalid Data",
True, "Good Data"
)
And this gives me the results that I expect, however, if I change Good Data with my expression to calculate the difference of weekdays between the two dates I still get a #Error. It looks like when I do this it doesn't recognize the Report Submitted Date as Nothing. Altered expression below:
=switch(
IsNothing(Fields!End_Date.Value),"Invalid Data",
IsNothing(Fields!Report_Submitted_Date.Value),"Invalid Data",
Fields!Report_Submitted_Date.Value <= Fields!End_Date.Value, "Invalid Data",
True, ((DateDiff(DateInterval.day,Fields!End_Date.Value,Fields!Report_Submitted_Date.Value)+1)
- (DateDiff(DateInterval.WeekOfYear,Fields!End_Date.Value,Fields!Report_Submitted_Date.Value)*2)
- IIF(Weekday(Fields!End_Date.Value,1) = 1,1,0)
- IIF(Weekday(Fields!End_Date.Value,1) = 7,1,0)
- IIF(Weekday(Fields!Report_Submitted_Date.Value,1) = 1,1,0)
- IIF(Weekday(Fields!Report_Submitted_Date.Value,1) = 7,1,0)-2)
)
Result:

uitable 'logical' selection checkboxes

I have a doubt regarding uitable of guide Matlab.
Currently what I would like to see is how can I print a string from a uitable. This string should be like this:
(['{''ElementA'', ''true'', ''ElementB'', ''false'', ''ElementN'', ''true/false'', ...
So in the uitable there is 3 columns:
Column 1: It shows de numbers of rows (total number of Elements)
Column 2: Titled "Elements" and it shows a list of all Element names. --> Format: Let Matlab choose
Column 3: Titled "Selection" where it appears checkboxes. ---> Format: logical
So depending on the state of each check box (true or false) I would like to print an string like:
ElementA, true, ElementB, false, etc...
Any ideas ?
Thanks in advance

Formula help needed

I am trying to write a report that is looking for someone that HAS NOT had a certain immunization. The problem is what ever I try for a formula it is saying they have had it or have not had the immunization. When I go to validate it is not always correct
if ({table.column} in (ID#) to (ID#)) then
"Has had Immunization"
else if ({table.column} <> (ID#) to (ID#))
then "Has not had Immunization"
ID# was the same number for all.
Record-selection formula:
// list desired immunization values; remove quotes if IDs are numeric
{table.field} IN [
'ID0',
'ID1',
...
'IDn'
]

How to skip hidden rows while iterating through Google Spreadsheet w/ Google Apps Script

I have a Google Spreadsheet with many hidden rows in it, and I want to skip them when iterating through a list of rows in the spreadsheet.
It's mainly an efficiency issue, as I'm dealing with over half of my rows being hidden and in no need of being checked.
Any help would be appreciated.
New API as of 2018 that's useful for this problem: isRowHiddenByUser. See also isRowFilteredByUser.
There's no direct way of doing this in Apps Script, but there is a feature request open to provide a way get the show/hide status of a row, if you want to star it.
A workaround using SUBTOTAL. Create 2 columns A and B. A must always have a value and B has a set of formulas. These 2 columns look like this:
A | B
---------------------------
1 | =NOT(SUBTOTAL(103, A1))
1 | =NOT(SUBTOTAL(103, A2))
1 | =NOT(SUBTOTAL(103, A3))
SUBTOTAL returns a subtotal using a specified aggregation function. The first argument 103 defines the type of function used for aggregation. The second argument is the range to apply the function to.
3 means COUNTA and counts the number of values in the range
+100 means ignore hidden cells in the range.
The result of SUBTOTAL with a range of 1 cell will be 0 when the cell is hidden and 1 when the cell is shown. NOT inverts it.
Now you can read the column B with your script to know if a row is hidden.
Here's the transposed question and answer: https://stackoverflow.com/a/27846180/1385429
The issue tracker holds that request since Aug 3, 2010 with a Medium priority and just a "Triaged" status. More than 3 years and no signs of solution from the GAS team.
My workaround was to use a special leading character that would indicate the visibility state of the row/column, it is a leading backtick (`) in the cells of top header row/column.
In case if merged cells are used in column headers, then an empty top row should be dedicated just for that functionality until the google engineers will improve the API.
Same applies if there are formulas in the 1st row/column cell(s).
These dedicated rows/columns itself can be hidden.
After starting to use this functionality each show/hide column/row command should be performed from a customized menu, otherwise there'll be errors when iterating through the range programmatically, because of the missing/excessive backtick.
e.g. to hide rows of selected cells the following function is invoked
function hideSelectedRows() {
var sheet = SpreadsheetApp.getActiveSheet();
var range = SpreadsheetApp.getActiveRange();
// hide rows and add a ` backtick to the header cell
for (var row = range.getRow(); row <= range.getLastRow(); row++)
{
// add backtick only if it isn't there (that may happen when manually unhiding the rows)
var cellHeader = sheet.getRange(row, 1)
var cellHeaderValue = cellHeader.getValue()
if ( !cellHeaderValue.match(/^`/) ) {
cellHeader.setValue('`' + cellHeaderValue)
}
// hide rows of selected range
sheet.hideRows( row );
}
}
and the menu
SpreadsheetApp.getActiveSpreadsheet()
.addMenu("Show/Hide", [
{ name : "Hide Selected Rows", functionName : "hideSelectedRows" },
{ name : "Hide Selected Columns", functionName : "hideSelectedColumns" },
null,
{ name : "Hide Rows", functionName : "hideRows" },
{ name : "Hide Columns", functionName : "hideColumns" },
null,
{ name : "Show Rows", functionName : "showRows" },
{ name : "Show Columns", functionName : "showColumns" },
null,
{ name : "Show All Rows", functionName : "unHideAllRows" },
{ name : "Show All Columns", functionName : "unHideAllColumns" }
])
Once google engineers find the time to improve the onChange event, it will be possible to put those backticks automatically. Currently the changeType is limited to EDIT, INSERT_ROW, INSERT_COLUMN, REMOVE_ROW, REMOVE_COLUMN, INSERT_GRID, REMOVE_GRID, OTHER without any details on which Row/Column was inserted/removed. Looks like the team behind GAS is scanty. I wish they could hire more programmers (khm khm)
As for workaround, it is possible by using SUBTOTAL function which can returns a subtotal for a vertical range of cells.
Syntax is:
SUBTOTAL(function_code, range1, [range2, ...])
where hidden values can be skipped for any of these codes by prepending 10 (to the single-digit codes).
For example 102 for COUNT while skipping hidden cells, and 110 for VAR while doing so.
Related: Google Spreadsheets sum only shown rows at Webapps SE