Is there a Way to add a prefix to the filter function so the result looks like this:
Prefix Value1
Prefix Value2
Prefix Value3
I already tried things like:
="Prefix "&FILTER(Data;condition1;condition2)
which resulted in just the first value of the filter getting returned with the prefix the rest didn't get returned.
Prefix Value1
also tried this:
=TEXTJOIN("Prefix ";FILTER(Data;condition1;condition2))
This resulted in:
Prefix ReturnValue1ReturneValue2ReturnValue3
so my current workaround is to just Filter in another column and in the column I want the prefix with the filter I just say
="Prefix "&B1
="Prefix "&B2
="Prefix "&B3
...
This results in about 8000 Cells that need to be recalculated each time something changes.
If you want to add the Prefix to the already filtered data you can use ARRAYFORMULA:
=ARRAYFORMULA("Prefix "&FILTER(Q:Q,Q:Q>3))
(Obviously, change the filter, it's just an example)
You can use the concatenate function or the '&' operator in your filter.
Function: https://support.google.com/docs/answer/3094123?hl=en
=FILTER([Range], CONCATENATE("Prefix ", [Range])="filtervalue")
=FILTER([Range], "Prefix " & [Range]="filtervalue")
use:
=INDEX("Prefix "&FILTER(Data; condition1; condition2))
example:
=INDEX("Prefix "&FILTER(A:C; B:B<>""; C:C<>""))
but you can use only FILTER too if you do it like:
=FILTER({"Prefix "&A:A\ B:C}; B:B<>""; C:C<>""))
Related
I am using importxml function to extract some info
=IMPORTXML("url","//span[#class='circle-with-text grade-D']")
I need to replace D with any other letter,trying to use "" or '' or '?' etc with no results.
"AN?" idea?
'=IMPORTXML("url","//span[#class='circle-with-text grade-D']")'.replace(/D/,"A"); It's the only capital D.
Use SUBSTITUTE.
As per the Help Docs:
SUBSTITUTE
Replaces existing text with new text in a string.
SUBSTITUTE(text_to_search, search_for, replace_with, [occurrence_number])
text_to_search - The text within which to search and replace.
search_for - The string to search for within text_to_search.
search_for will match parts of words as well as whole words; therefore a search for "vent" will also replace text within "eventual".
replace_with - The string that will replace search_for.
occurrence_number - [ OPTIONAL ] - The instance of search_for within text_to_search to replace with replace_with. By default, all occurrences of search_for are replaced; however, if occurrence_number is specified, only the indicated instance of search_for is replaced.
So:
=IMPORTXML("url",SUBSTITUTE("//span[#class='circle-with-text grade-D']", "D", "A"))
replaces all Ds in the formula with As.
I have a field in the database which contains strings that look like: 58XBF2022L1001390 I need to be able to query results which match the last letter(in this case 'L'), and match or resemble the last four digits.
The regular expression I've been using to find records which match the structure is: \d{2}[A-Z]{3}\d{4}[A-Z]\d{7}, So far I've tried using a scope to refine the results, but I'm not getting any results. Here's my scope
def self.filter_by_shortcode(input)
q = input
starting = q.slice!(0)
ending = q
where("field ~* ?", "\d{2}[A-Z]{3}\d{4}/[#{starting}]/\d{3}[#{ending}]\g")
end
Here are some more example strings, and the substring that we would be looking for. Not every string stored in this database field matches this format, so we would need to be able to first match the string using the regex provided, then search by substring.
36GOD8837G6154231
G4231
13WLF8997V2119371
V9371
78FCY5027V4561374
V1374
06RNW7194P2075353
P5353
57RQN0368Y9090704
Y0704
edit: added some more examples as well as substrings that we would need to search by.
I do not know Rails, but the SQL for what you want is relative simple. Since your string if fixed format, once that format is validated, simple concatenation of sub-strings gives your desired result.
with base(target, goal) as
( values ('36GOD8837G6154231', 'G4231')
, ('13WLF8997V2119371', 'V9371')
, ('78FCY5027V4561374', 'V1374')
, ('06RNW7194P2075353', 'P5353')
, ('57RQN0368Y9090704', 'Y0704')
)
select substr(target,10,1) || substr(target,14,4) target, goal
from base
where target ~ '^\d{2}[A-Z]{3}\d{4}[A-Z]\d{7}$';
Let's say I have a query:
Foo.where("lower(bar) LIKE ?", "%#{baz}%")
which transforms to plain SQL as:
... WHERE (lower(bar) LIKE ...
and works perfectly. But instead of bar I want to pass an argument. So I tried to rewrite it like this:
Foo.where("lower(?) LIKE ?", bar, "%#{baz}%")
where bar is a variable containing a string 'bar'. In this case it stops working and transforms to plain SQL as:
... WHERE (lower('bar') LIKE ...
So how can I make this query work?
You might want to try using sprintf-style % escapes in the template to avoid the the column name you wish to interpolate from being quoted:
Foo.where("lower(%s) LIKE '%s'", bar, "%#{baz}%")
(N.B. The single quotes around the second %s - the second argument does want to be quoted)
Reference:
Lastly, you can use sprintf-style % escapes in the template. This works slightly differently than the previous methods; you are responsible for ensuring that the values in the template are properly quoted. The values are passed to the connector for quoting, but the caller is responsible for ensuring they are enclosed in quotes in the resulting SQL. After quoting, the values are inserted using the same escapes as the Ruby core method Kernel::sprintf.
You can construct your query via Arel:
bar = :field_name # or 'string_name'.to_sym
Foo.where(Foo.arel_table[bar].lower.matches("%#{baz}%"))
I have a field which value is an array of strings.
Example: Mom, dad, son, etc.
It is possible to repeat a link with those values?
Example:
Mom
dad
son
And when I click on the link to have a href=www."fieldvalue".com.
EDIT: it is not vector, it is Array.
Create your repeat control. For the value add in your field name. Something like :
document1.getItemValue("myMultiValueField")
I THINK that should repeat your field assuming it is a real multi-value. The comma deliminated string would require more work. So I'm not talking about that...
Make sure the collection name / var name of the repeat is something like "rowData"
rowData should then be a String.
Drop a link control inside the repeat.
Compute the label to be simple "rowData". (no quotes in the code)
Compute the URL - which I THINK is "value" in all properties of the link
That's just javaScript so you should be able to do something like:
return "http://" + rowData + ".com"
That's rough - you'll have to play with it but if I follow you correctly should work.
For a comma deliminated String... in the repeat control you'd need to use SSJS or #functions to break that into an array so the repeat can work on it.
In your repeat you'll need to map the value attribute to the Vector and set a var property, which is how you will reference each element. Note: a comma-separated string is a single value, and a repeat requires multiple values. So you'll need to convert it to a Vector or some other multi-value object.
Within the repeat you can use any other control and compute the value as you would elsewhere. To access each element in your repeat control's source (i.e. each String in your Vector, in this case), use the variable name you've defined in the var property.
I have a simple questio: how to get/set checkbox from checkboxes in orbeon?
Something like this:
/myCheckboxes[value="itemVal"].isChecked()
That's right, the values are space-separated. To extract them, instead of contains() use this to check if value 42 is included:
tokenize(../myCheckboxGroup, '\s+') = '42'
This splits the value on spaces with the \s+ regexp and returns a string sequence.
By the way you don't need to write:
if (condition) true() else false()
You can always just write:
condition
i've made something like this:
to set: simply set value of checkbox group as a string compound by all items values i want to have checked separated by a space.
To check if checkbox is checked i`ve made something like this:
if(contains(../myCheckboxGroup, '2')) then true() else false()
but its not good solution for example because it's making that max items is 10 if i want to add values as a successive integers.