Refining a Query formula with two 'where' conditions - google-sheets

I need to write a Query formula to pull through unique values from another sheet, excluding rows that contain certain keywords and also excluding any empty rows.
I've written this formula:
=UNIQUE(QUERY('Sheet Name'!A1:AZ,"Select A where A is not null and where not A contains 'STRING'",1))
Unfortunately this gives a VALUE error. It works with either of the 'where' clauses but not with both.
What am I missing?

You don't need to add the seconde 'Where', it just implies that you continue to add conditions into that statement:
=UNIQUE(QUERY('Sheet Name'!A1:AZ,"Select A where A is not null and not A contains 'STRING'",1))

Related

PowerAutomate : Get max columnvalue From dataverse table

I have a Dataverse table named my_sample_table.
Inside the table I have a column named my_sample_column of type integer whose max value should be returned. Am trying to achieve this by using the List rows action provided with PowerAutomate.
Is there a filter query that can be written on the Filter rows property ? similar to what we use with SQL : max(columnname)
Or any other queries that can be included in the List rows action which will return the same result.
I know that I can iterate through the column values to get the max value using an expresion or by sorting it and getting the topmost one. But I was wondering whether there are any direct approach to it.
I would try and use a max aggregate for this column in a Fetch Xml query:
https://learn.microsoft.com/en-us/power-apps/developer/data-platform/use-fetchxml-aggregation#max

(Neo4j 3.5) Executing query with two parts and the second one consists on a group of matches where at least one needs to be fulfilled

we are trying to run a cypher query but we are not able to get the results we want.
It is important to note that we cannot make this work with subqueries because we are using Neo4j 3.5 and in this version, they are still not available.
The problem is that we have two parts for a query, the first one will fix the variables for the second part, and the second part consists of multiple matches, and it has to get the results of the previous query and if at least one of the matches return a result for a row, this row is not filtered out, else if none return result it is discarded.
More specifically, the query we are trying to run is similar to the following one:
//First part of the query where we want to fix variables with the match and where
MATCH (u:User)-[:ASSIGNED_TO]->(t:Task)-[:PENDING]->(ob:Object)<-[:HAS_OPEN_OBJECT]-(do:DataObject)<-[:ASOCIATED]-(:Module)-[:CAN_LIST]->(view:WidgetObject)
WHERE u.uid = 'user_uid'
AND view.uid = 'view_uid'
AND view.object_name = do.object_type
with do, t, ob
// In this second part of the query we want to maintain the variables of the previous part and if at least one matches the value should be returned
// we have tried with UNION but we will need pagination, but even with union it's not working
MATCH (ac:Action)<-[:ASOCIATED]-(t)-[rel:COMPLETED|PENDING]->(ob)<-[:HAS_OPEN_OBJECT|HAS_CLOSED_OBJECT]-(do)
WHERE ac.name CONTAINS 'body'
WITH COLLECT({data_object_uid: do.uid}) as act_filter
MATCH (c:Comment)<-[:COMMENTED]-(t)-[rel:COMPLETED|PENDING]->(ob)<-[:HAS_OPEN_OBJECT|HAS_CLOSED_OBJECT]-(do)
WHERE c.body CONTAINS 'body'
WITH act_filter + COLLECT({data_object_uid: do.uid}) as comment_filter
MATCH (at:Attachment)<-[:HAS_ATTACHMENT]-(t)-[rel:COMPLETED|PENDING]->(ob)<-[:HAS_OPEN_OBJECT|HAS_CLOSED_OBJECT]-(do)
WHERE at.name CONTAINS 'body'
WITH comment_filter + COLLECT({data_object_uid: do.uid}) as attachment_filter
UNWIND attachment_filter as row
return row.data_object_uid
We are not sure if in the second part, the second and third matches are maintaining the same subset of results coming from the first part of the query.
A funny behavior we have found is that if we remove the last match we are getting results but if we add it, we are not getting any results. We do not understand this behavior because if the second match is returning results and they are stored in a variable after a collect, appending this to the next collected results should return something.
For example, if the second match returns as comment_filter [{data_object_uid: "343dienmd3-dasd"}] and the third match is not returning anything, after the concatenation in the WITH clause it should return the same thing, but the result is empty.
We need some light here, we don't know if we are close and we are making a stupid mistake or we are getting all wrong and we need to change the approach completely.
Since you do not know which of the three matches in the second part will yield results, I would try something along the lines below:
NOTE I used ASSOCIATED instead of ASOCIATED
MATCH (n)<-[:ASSOCIATED|COMMENTED|HAS_ATTACHMENT]-(t)-[rel:COMPLETED|PENDING]->(ob)<-[:HAS_OPEN_OBJECT|HAS_CLOSED_OBJECT]-(do)
WHERE
(n:Action AND n.name CONTAINS 'body')
OR
(n:Comment AND n.body CONTAINS 'body')
OR
(n:Attachment AND n.name CONTAINS 'body')
RETURN COLLECT(DISTINCT {data_object_uid: do.uid})

Resolve DGET function "More than one match found" error

I am trying to match a list of range with certain criteria in a google spreadsheet. I am using DGET function for the same. Everything is working fine but the problem comes when there are many entries that contain the whole string and I receive "More than one match found in DGET evaluation.".
For the better understanding look below:
Sheet "Form Responses 1":
B
-------
Ronald
Ronaldo
Ronaldinho
Rebarto
Matching sheet entries:
A
------
Ronald
Rebarto
Juhino
My Formula is:
=DGET('Form Responses 1'!B:H,"Date",{"Email Address","Logging In or Logging out ?","Date";A2,$B$1,$H$1})
Now the problem is Ronald is matching with "Ronald","Ronaldo" and "Ronaldinho" and I am receiving the error which says "multiple entries found".
How do we solve this?
I solved the problem by Concatenating a constant variable before and after the name. For example Ronaldo becomes mRonamdom and Ronald becomes mRonaldm. This makes the Names Unique and solves the problem.
If you don't want to modify the data but to fix the formula so it doesn't get confused with similar entries in your database parameter you can add a character to the criteria field of the dget function as shown below (I'm using an '=' sign concatenated to the value I want to match with in the database parameter)
=dget(database!$A$1:$B$11,$M$1,{"columnName";"="&F2})
where
A1:B11 is my database
M1 is the matching column name
and "="&F2 is the field with the caracter I chose that I want to match with to retrieve values from the matching database column, now even if the there are more than one matches found (becuase matching substrings"), the addition of the caracter contatenated with the matching value, should take care of the in-accurate error.

Issue regarding fetching only those records where field value contains only one occurrence of a particular character in rails

I need to write a rails active record where clause where I have to fetch those rows where name (name is a column in my table) contains only one occurrence of the character '.'
For example, if there is two rows in the table where name is "a.b" and "a.b.c", then my query should return the row having name "a.b" only.
Please help me to solve this.
Thanks in advance!
You can for example remove the dots and compare length.
SELECT * FROM table WHERE (char_length(name) - char_length(replace(name, '.', '')))=1
This is not very efficient though, because indexes can't be utilized.
To make things smoother, you could store the number of dots (depth?) in its own column with an index and query based on that. This could be done in insert/update trigger or in application layer, whatever suits your situation.
dbfiddle
with regexp ? you can try this :
select * from "table" where "name" ~ '^[^\.]*\.[^\.]*$'

Excluding one column from forEach

I'm using the following expression to return an md5 hash of a concatenation of all values in a row.
md5(forEach(row.columnNames,cn,if(isNull(cells[cn]),"",cells[cn].value)).join("|"))
This is to create an easy index for identifying duplicates (I do not wish to remove them at this stage). However, I've just realised that because one of the columns contains the unique index for the data set, I cannot hash every column as the inclusion of this column will obviously make every hash unique! (duh)
Is there a way to exclude a nominated column from the forEach loop? A sort of forEach except this...
Thanks
Assuming the column you want to exclude is the first one, you can subset row.columnNames like this:
md5(forEach(row.columnNames.slice(1),cn,if(isNull(cells[cn]),"",cells[cn].value)).join("|"))
If you prefer to exclude a column by its name (for example, "ID"), you should use filter() :
md5(forEach(filter(row.columnNames, v, v!="ID"),cn,if(isNull(cells[cn]),"",cells[cn].value)).join("|"))
Similarly, you can also use filter()to include/exclude column names based on conditions (here : exclude columns that contain a capital "C" in their name):
filter(row.columnNames, v, v.contains("C")==false)

Resources