根据多个条件查询单列和填充列的值

问题描述 投票:1回答:2

我试图仅查询满足特定条件的客户端的ID,从源选项卡到输出选项卡,并根据条件使用静态值填充2列,使用动态值填充2列。

在源选项卡中,我有:

+-----------------------+------+
| Status                | ID   |
+-----------------------+------+
| Retired/Deceased      | 2a33 |
+-----------------------+------+
| Liquidation           | 1sTR |
+-----------------------+------+
| Dissolved             | 3B76 |
+-----------------------+------+
| Released from company | 463z |
+-----------------------+------+
| Active                | 557g |
+-----------------------+------+
| In progress           | zz34 |
+-----------------------+------+
| Demo                  | cc56 |
+-----------------------+------+

请注意,有7个标准值,我只需要4个输出。这意味着我需要4个值,根据这些值将存在动态列的二进制填充。其他3个值已过时。

从这4个值,如果我有例如。标准1,然后我将填充2个动态列,如果没有(对于其他3个值),我将有其他填充值。

所以我想简单地使用二进制解决方案来选择特定值是不适用的。

在输出选项卡逻辑中:

+--------------------------------------------------------------------------------+
|                                   Output tab                                   |
+--------------------------------------------------------------------------------+
| ID | Status | Reason | Comment                    | Detail                     |
+----+--------+--------+----------------------------+----------------------------+
| A1 | Static | Static | If criteria = criteria 1,  | If criteria = criteria 1,  |
|    |        |        |    then null,              |    then value 1,           |
|    |        |        |    else criteria value     |    else value 2            |
+----+--------+--------+----------------------------+----------------------------+
| B1 | Static | Static | If criteria = criteria 1,  | If criteria = criteria 1,  |
|    |        |        |    then null,              |    then value 1,           |
|    |        |        |    else criteria value     |    else value 2            |
+----+--------+--------+----------------------------+----------------------------+
| C1 | Static | Static | If criteria = criteria 1,  | If criteria = criteria 1,  |
|    |        |        |    then null, else         |    then value 1,           |
|    |        |        |    criteria value          |    else value 2            |
+----+--------+--------+----------------------------+----------------------------+
| D1 | Static | Static | If criteria = criteria 1,  | If criteria = criteria 1,  |
|    |        |        |    then null,              |    then value 1,           |
|    |        |        |    else criteria value     |    else value 2            |
+----+--------+--------+----------------------------+----------------------------+
| E1 | Static | Static | If criteria = criteria 1,  | If criteria = criteria 1,  |
|    |        |        |    then null,              |    then value 1,           |
|    |        |        |    else criteria value     |    else value 2            |
+----+--------+--------+----------------------------+----------------------------+
| F1 | Static | Static | If criteria = criteria 1,  | If criteria = criteria 1,  |
|    |        |        |    then null,              |    then value 1,           |
|    |        |        |    else criteria value     |    else value 2            |
+----+--------+--------+----------------------------+----------------------------+
| G1 | Static | Static | If criteria = criteria 1,  | If criteria = criteria 1,  |
|    |        |        |    then null,              |    then value 1,           |
|    |        |        |    else criteria value     |    else value 2            |
+----+--------+--------+----------------------------+----------------------------+

虚拟输出选项卡:

+-----------------------+------+-------------------+-------------+------------------+---------------------------------+
| Status                | ID   | Status            | Reason      | Comment          | Detail                          |
+-----------------------+------+-------------------+-------------+------------------+---------------------------------+
| Retired/Deceased      | 2a33 | Unable to proceed | Unspecified | Retired/Deceased | Retired/No longer in business   |
+-----------------------+------+-------------------+-------------+------------------+---------------------------------+
| Liquidation           | 1sTR | Unable to proceed | Unspecified | Liquidation      | Retired/No longer in business   |
+-----------------------+------+-------------------+-------------+------------------+---------------------------------+
| Dissolved             | 3B76 | Unable to proceed | Unspecified | Dissolved        | Retired/No longer in business   |
+-----------------------+------+-------------------+-------------+------------------+---------------------------------+
| Released from company | 463z | Unable to proceed | Unspecified | (null)           | No longer works for the company |
+-----------------------+------+-------------------+-------------+------------------+---------------------------------+

“状态”列不是必需的。我添加它只是为了参考和可读性。

道歉,但我对共享Google表格链接有公司安全限制。

我最挣扎的部分是第4列(动态中的第一个)需要从源选项卡返回第2列中的条件值。

到目前为止,我一直在查询的第一部分,我根据多个条件QUERY ID,标记并填充静态值列。

=QUERY(Data!$A$3:$BN, 
    "SELECT B, 'Unable to proceed', 'Unspecified' 
     WHERE A = 'Retired/Deceased' 
      OR A = ''Liquidation' 
      OR A = 'Dissolved'  
      OR A = 'Released from company' 
      AND A IS NOT NULL
     LABEL 'Unable to proceed' 'Unspecified' , 'Status' 'Reason'", 1)

但是,基于多个标准,我正在努力使用动态列。

我用ARRAYFORMULAIFERROR在嵌套的VLOOKUP中查找了QUERY,但是无法绕过它。

另外,如果有超过2个值的选项来填充输出选项卡中的第3列和第4列,我对如何工作非常感兴趣。据我所知,基于标准解决2个值的方法是嵌套IFERROR函数以使其成为二进制。但是如果有多于2个值来填充数组呢?

google-sheets google-sheets-formula google-sheets-query
2个回答
1
投票

根据状态:

=QUERY({QUERY(Data!$A$1:$B, 
        "SELECT B, 'Unable to proceed', 'Unspecified' 
         WHERE A = 'Retired/Deceased' 
            OR A = 'Liquidation' 
            OR A = 'Dissolved'  
            OR A = 'Released from company' 
           AND A IS NOT NULL
         LABEL 'Unable to proceed''Status', 'Unspecified''Reason'", 1),
        QUERY(ARRAYFORMULA(IFERROR(VLOOKUP(
        QUERY(Data!$A$2:$B, 
        "SELECT A
         WHERE A = 'Retired/Deceased' 
            OR A = 'Liquidation' 
            OR A = 'Dissolved'  
            OR A = 'Released from company' 
           AND A IS NOT NULL", 0), 
 {"Retired/Deceased",      "Retired/Deceased", "Retired/No longer in business";
  "Liquidation",           "Liquidation",      "Retired/No longer in business";
  "Dissolved",             "Dissolved",        "Retired/No longer in business";
  "Released from company", "",                 "No longer works for the company"}, {2, 3}, 0), )), 
        "LABEL Col1 'Comment', Col2 'Detail'", 0)}, , 0)

0


1
投票

基于ID:

=QUERY({QUERY(Data!$A$1:$B, 
        "SELECT B, 'Unable to proceed', 'Unspecified' 
         WHERE A = 'Retired/Deceased' 
            OR A = 'Liquidation' 
            OR A = 'Dissolved'  
            OR A = 'Released from company' 
           AND A IS NOT NULL
         LABEL 'Unable to proceed''Status', 'Unspecified''Reason'", 1),
        QUERY(ARRAYFORMULA(IFERROR(VLOOKUP(
        QUERY(Data!$A$2:$B, 
        "SELECT B
         WHERE A = 'Retired/Deceased' 
            OR A = 'Liquidation' 
            OR A = 'Dissolved'  
            OR A = 'Released from company' 
           AND A IS NOT NULL", 0), 
 {"2a33", "Retired/Deceased", "Retired/No longer in business";
  "1sTR", "Liquidation",      "Retired/No longer in business";
  "3B76", "Dissolved",        "Retired/No longer in business";
  "463z", "",                 "No longer works for the company"}, {2, 3}, 0), )), 
        "LABEL Col1'Comment', Col2'Detail'", 0)}, , 0)

© www.soinside.com 2019 - 2024. All rights reserved.