= date'" & TEXT(DATEVALUE(J$4);"y" /> = date'" & TEXT(DATEVALUE(J$4);"y" /> = date'" & TEXT(DATEVALUE(J$4);"y"/>

How to run Google-sheets query on text cell containing asterisk

496 views Asked by At

When I use this query in Google sheets

=QUERY('Kontoutdrag länsförsäkringar'!$A$3:$F$1000186;"SELECT sum(F) WHERE B >= date'" & TEXT(DATEVALUE(J$4);"yyyy-mm-dd") & "' AND B <= date '"& TEXT(DATEVALUE(J$5);"yyyy-mm-dd") &"' AND D matches '" & JOIN("|";$T10:$CZ10) &"' AND D != '' label sum(F)'' ")

It will skip any cell that contains an asterisk somewhere in the text, the character

*

The error is in this match part

AND D matches '" & JOIN("|";$T10:$CZ10)

If the D column's text (and the corresponding, identical cell in the join range) contains an asterisk it will not match.

Is there a way to escape this so that I can have cells with the asterisk in the text?

This value will work

K Batteriexp

This value will not be picked up by the query

K*Batteriexp
1

There are 1 answers

0
TheMaster On

If asterisk is the only problem, You can escape it using regex:

AND D matches '" & ARRAYFORMULA(JOIN("|";REGEXREPLACE($T10:$CZ10,"\*","\\*")))

This

K*Batteriexp //Means 'K' repeated 0 or more times

becomes

K\*Batteriexp //means a literal *