嵌套正则表达式匹配不适用于零和一的范围
Nested Regexmatch Not Working on Range of Zeros and Ones
我有一个求和过滤器公式,并在其中嵌套了一个 REGEXMATCH 函数,作为过滤求和范围的条件。
完整的公式如下:
=sum(filter(data,
region1=$AF,
industry=$A11,
quarter=AG,
REGEXMATCH(consent,"1")))
范围 "consent" 范围内的每个值仅为 0 或 1。
当我 运行 这个函数返回 0 而我期望大约 1,000。
documentation for REGEXMATCH 表示
"This function only works with text (not numbers) as input and returns
text as output. If a number is desired as the output, try using the
VALUE function in conjunction with this function. If numbers are used
as input, convert them to text using the TEXT function."
我不知道该怎么办。我尝试了以下方法:
REGEXMATCH(consent,1) // no luck
REGEXMATCH(TEXT(consent),"1") // no luck
REGEXMATCH(TEXT(consent),TEXT(1)) // no luck
但是,如果我这样做:
REGEXMATCH(consent,".*") // does work for all data in consent
我如何告诉 GSheets 在范围同意等于 1 时进行 REGEXMATCH?
我认为文档有点误导,因为虽然您可以使用 TEXT
函数(requires a second argument that prescribes the format of the output,这就是您的尝试无效的原因)转换为文本,但它可能是这不是最简单的方法。可能更好的做法是 TO_TEXT
,或者简单地附加 &""
:
REGEXMATCH(TO_TEXT(consent),"1")
REGEXMATCH(consent&"","1")
话虽如此,您是否有理由不能只使用 consent=1
(在这种情况下,您可以单独使用 consent
作为 FILTER
中的参数) ?
我有一个求和过滤器公式,并在其中嵌套了一个 REGEXMATCH 函数,作为过滤求和范围的条件。
完整的公式如下:
=sum(filter(data,
region1=$AF,
industry=$A11,
quarter=AG,
REGEXMATCH(consent,"1")))
范围 "consent" 范围内的每个值仅为 0 或 1。
当我 运行 这个函数返回 0 而我期望大约 1,000。
documentation for REGEXMATCH 表示
"This function only works with text (not numbers) as input and returns text as output. If a number is desired as the output, try using the VALUE function in conjunction with this function. If numbers are used as input, convert them to text using the TEXT function."
我不知道该怎么办。我尝试了以下方法:
REGEXMATCH(consent,1) // no luck
REGEXMATCH(TEXT(consent),"1") // no luck
REGEXMATCH(TEXT(consent),TEXT(1)) // no luck
但是,如果我这样做:
REGEXMATCH(consent,".*") // does work for all data in consent
我如何告诉 GSheets 在范围同意等于 1 时进行 REGEXMATCH?
我认为文档有点误导,因为虽然您可以使用 TEXT
函数(requires a second argument that prescribes the format of the output,这就是您的尝试无效的原因)转换为文本,但它可能是这不是最简单的方法。可能更好的做法是 TO_TEXT
,或者简单地附加 &""
:
REGEXMATCH(TO_TEXT(consent),"1")
REGEXMATCH(consent&"","1")
话虽如此,您是否有理由不能只使用 consent=1
(在这种情况下,您可以单独使用 consent
作为 FILTER
中的参数) ?