QUERY simplification with LAMBDA function - google-sheets

I have this formula so I want to make the same QUERY for each variable and join the results. The given formula works (no error in cell) but it give me only the first query result.
I want the result to be QUERYRESULT1 / QUERYRESULT2 / QUERYRESULT3, etc. and i could repeeat the query for each variable, but I'm asking for a way to make it with only one line (to simplify). Is it possible?
=MAP(
BI3:BI;BL3:BL;BO3:BO;BR3:BR;BU3:BU;BX3:BX;CA3:CA;CD3:CD;CG3:CG;CJ3:CJ;CM3:CM;CP3:CP;
LAMBDA(f;g;h;i;j;k;l;m;n;o;p;q;
TEXTJOIN(" / "; TRUE;
IFNA(
ARRAYFORMULA(
IFERROR(QUERY('BDD Componentes'!AR:AV;"SELECT AV WHERE AR = '"&{f;g;h;i;j;k;l;m;n;o;p;q}&"'";0))
)
)
)
)
)

here I am with the same suggestion as in your previous question. Try it and let me know:
=BYROW({BI3:BI\BL3:BL\BO3:BO\BR3:BR\BU3:BU\BX3:BX\CA3:CA\CD3:CD\CG3:CG\CJ3:CJ\CM3:CM\CP3:C};
LAMBDA(r;
TEXTJOIN(" / "; TRUE;
IFNA(
ARRAYFORMULA(
IFERROR(QUERY('BDD Componentes'!AR:AV;"SELECT AV WHERE AR = '"&r&"'";0))
)
)
)
)
)

Related

How to ArrayFormula in Google Sheets with multiple IF AND OR conditions?

Can someone please help me?
I can't get seems to work it.
What else should I do?
Here is my code
=ARRAYFORMULA(IF(AND(Y2:Y="VUL",L2:L="ANNUAL"),V2:V*0.03,IF(AND(Y2:Y="VUL",L2:L="QUARTERLY"),V2:V>0,IF(AND(Y2:Y="VUL",L2:L="SEMI ANNUAL"),V2:V*AB2:AB,"0"))))
The results must be from 2nd row to last but only works only for 2nd row.
Use ifs(), like this:
=arrayformula(
ifs(
Y2:Y <> "vul", iferror(1/0),
L2:L = "annual", V2:V * 0.03,
L2:L = "quarterly", V2:V > 0,
L2:L = "semi annual", V2:V * AB2:AB,
true, iferror(1/0)
)
)
use:
=ARRAYFORMULA(IF((Y2:Y="VUL")*(L2:L="ANNUAL"), V2:V*0.03,
IF((Y2:Y="VUL")*(L2:L="QUARTERLY"), V2:V>0,
IF((Y2:Y="VUL")*(L2:L="SEMI ANNUAL"), V2:V*AB2:AB, "0"))))
AND is *
OR is +
Got the rights answer
thank you so much guys
=ARRAYFORMULA(IF((Y2:Y="VUL")*(L2:L="ANNUAL"),V2:V*0.03,
IF((Y2:Y="VUL")*(L2:L="QUARTERLY")*(V2:V>0), V2:V*AB2:AB,
IF((Y2:Y="VUL")*(L2:L="SEMI ANNUAL")*(V2:V>0), V2:V*AB2:AB, "0"))))

And function in google sheets not working with complex funtions

=IF(
K22;
ARRAY_CONSTRAIN(
FILTER(
Pockets2.0!A:E;
Pockets2.0!A:A;
REGEXMATCH(Pockets2.0!C:C;"MTC");
K22=Pockets2.0!A:A;
O22=IF(
AND(REGEXMATCH(Pockets2.0!C:C;"MTC-.*$");TRUE());
-1;
1
) * Pockets2.0!D:D
);
1;
5
);
)
if I quit the and and just put the first statement it works, but with 'and' and true it fails
The and() function is an aggregating function and will not give row-by-row results in an array formula the way you seem to expect. To make it work, use Boolean arithmetic, like this:
=filter(
Pockets2.0!A:E,
K22 = Pockets2.0!A:A,
regexmatch(Pockets2.0!C:C, "mtc"),
O22 = if( regexmatch(Pockets2.0!C:C, "mtc-") * (true = true), -1, 1 ) * Pockets2.0!D:D
)

Lua gsub second instance

I'm using
local mystring = 'Thats a really nice house.'
string.gsub(mystring,"% ", "/",1)
to replace the first white space character with an slash.
But how to replace only the second occurrence of the white space?
You can use a function as replacement value in string.gsub and count the matches yourself:
local mystring = "Thats a really nice house."
local cnt = 0
print( string.gsub( mystring, " ", function( m )
cnt = cnt + 1
if cnt == 2 then
return "/"
end
end ) )
Try string.gsub(mystring,"(.- .-) ", "%1/",1).
You can replace the first instance with something else (assuming the replacement is not present in the string itself, which you can check), then replace it back:
print(mystring:gsub("% ", "\1",1):gsub("% ", "/",1):gsub("\1","% ", 1))
This prints: Thats a/really nice house.. Also, you don't need to escape spaces with %.

How do I get the table length of a lua table in c?

I have a c function that is called from lua. The first parameter is a table. That table is abused as an input array of numbers to an underlying api. So right now my code looks like this:
int n = 0;
lua_pushnil ( L );
while ( lua_next ( L, 2 ) ) {
n++;
lua_pop ( L, 1 );
}
int *flat = alloca ( n * 4 );
lua_pushnil ( L );
int i = 0;
while ( lua_next(L,2) ) {
flat[i++] = (int)lua_tonumber( L, -1 );
lua_pop ( L, 1 );
}
I typed the code blind, so please forgive errors. Also no error checking. But the problem is that I have to do the while loop twice. Is there an easy way to avoid that? I want to optimize for the case where the input is good - a table of ints.
The function you're looking for is unintuitively named lua_objlen, or in Lua 5.2, lua_len (there is a lua_rawlen if you wish to avoid metamethod invocations). It serves many roles (though some, like the length of a string, aren't very useful when you can just use lua_tolstring to get the string and its length), so you should be familiar with it.

Google Plus Count url

I'm trying to get the count of plus one's I have for google plus, I am checking to see if I have the count right with this
https://plusone.google.com/u/0/_/%2B1/fastbutton?count=true&url=MY_URL
I see that google plus rejects my URL (doesn't return 0 or anything)
I wanted to know if anyone can tell me if I have anything wrong in my url, I have these symbols in my url outside of letters and numbers
:
/
.
?
=
&
_
and my url is formatted like this
(protocol)://(server [such as www]).(domain)/(text).php?(text)=(text)&(text)=(digits)&(text)=(text)
Use the URL
https://plusone.google.com/_/+1/fastbutton?url=http%3A%2F%2Fwww.yoursite.com%2Fpath%2Fyour%2fcontent
instead and follow the solution found in this question (parse for window.__SSR = {c:)
I think you're looking for this. It's ugly and Google clearly doesn't support it, but it still works.
function shinra_gplus_get_count( $url ) {
$contents = file_get_contents(
'https://plusone.google.com/_/+1/fastbutton?url='
. urlencode( $url )
);
preg_match( '/window\.__SSR = {c: ([\d]+)/', $contents, $matches );
if( isset( $matches[0] ) )
return (int) str_replace( 'window.__SSR = {c: ', '', $matches[0] );
return 0;
}

Resources