2017-10-18 76 views
0

我想通過查詢填寫一個網格區域。但我希望此查詢根據下拉列表的選擇進行更改。我有三個不同的查詢,我希望他們根據下拉進行交換。使用IFS()在查詢語句之間切換

我試圖使用IFS如下面的查詢之間進行切換:

=iferror(
    IFS(B9="Value", 
       query(LOG!A4:U,"SELECT A, B, C, D, E, F, G, H, I, J, K WHERE A Is Not Null " 
       & IF(ISBLANK(B4),"", " AND K='"& LEFT(B4,7) &"'") & " " 
       & IF(D6<>"ALL", " AND N ='"& D6 &"'", "") & " " 
       & IF(E6<>"ALL", " AND Q ='"& E6 &"'", "") & " " 
       & IF(F6<>"ALL", " AND P ='"& F6 &"'", "") & " " 
       & IF(G6<>"ALL", " AND O ='"& G6 &"'", "") & " " 
       & IF(H6<>"ALL", " AND R ='"& H6 &"'", "") & " " 
       & IF(I6<>"ALL", " AND S ="& I6, "") & " " 
       & IF(ISBLANK(J6), "", " AND T ='"& LEFT(J6,7) &"'") & " " 
       & IF(ISBLANK(H9), "", " AND C >= date '" & text(H9,"yyyy-MM-dd") & "'") & " " 
       & IF(ISBLANK(I9), "", " AND D <= date '" & text(I9,"yyyy-MM-dd") & "'") & " " 
       ,-1), 
      B9 = "value 2", 
     "other query 
,"NO RESULTS") 

那麼單元格的值是不是查詢的價值,而這個公式只返回B9的價值。

有沒有辦法根據單元格的下拉選擇執行不同的查詢?

在此先感謝

編輯1:

=IFS(B9="WITHOUT COURSE" 
    ,FILTER(PERSONNEL!A6:J 
      ,(ISERROR(Match(PERSONNEL!A6:A,UNIQUE(filter(LOG!K4:K, VALUE(LOG!J4:J) = VALUE(RIGHT(B6,12)))),0))) 
      , (PERSONNEL!F6:F = E6) + (E6 = "ALL") 
      , (D6 = "ALL") + (PERSONNEL!D6:D = D6) 
      , (F6 = "ALL") + (PERSONNEL!G6:G = F6) 
      , (G6 = "ALL") + (PERSONNEL!E6:E = G6) 
      , (H6 = "ALL") + (PERSONNEL!I6:I = H6) 
      , (I6 = "ALL") + (PERSONNEL!H6:H = I6) 
    ) 
    ,B9="WITH COURSE" 
    ,query(LOG!A4:U,"SELECT A, B, C, D, E, F, G, H, I, J, K WHERE A Is Not Null " 
     & IF(ISBLANK(B4),"", " AND K='"& LEFT(B4,7) &"'") & " " 
     & IF(D6<>"ALL", " AND N ='"& D6 &"'", "") & " " 
     & IF(E6<>"ALL", " AND Q ='"& E6 &"'", "") & " " 
     & IF(F6<>"ALL", " AND P ='"& F6 &"'", "") & " " 
     & IF(G6<>"ALL", " AND O ='"& G6 &"'", "") & " " 
     & IF(H6<>"ALL", " AND R ='"& H6 &"'", "") & " " 
     & IF(I6<>"ALL", " AND S ="& I6, "") & " " 
     & IF(ISBLANK(J6), "", " AND T ='"& LEFT(J6,7) &"'") & " " 
     & IF(ISBLANK(H9), "", " AND C >= date '" & text(H9,"yyyy-MM-dd") & "'") & " " 
     & IF(ISBLANK(I9), "", " AND D <= date '" & text(I9,"yyyy-MM-dd") & "'") & " " 
     & IF(ISBLANK(B6), "", " AND J ='"& RIGHT(B6,12) &"'") & " " 
     & IF(ISBLANK(B7), "", " AND L ='"& RIGHT(B7,12) &"'") & " " 
     & IF(ISBLANK(B8), "", " AND M ='"& B8 &"'") & " " 
     & IF(B9 = "EXPIRES IN", " AND (DATEDIFF(now(), C)/30) >= U AND U > 0 AND (DATEDIFF(now(), C)/30) <= " &E9 & " " ,"") 
    ,-1) 
) 
+0

你錯過了分號:''other query「'? –

+0

我看不到一個;在opffical文檔https://support.google.com/docs/answer/7014145?hl=zh_CN中,如果我添加一個,它會自動刪除 –

+0

對不起,我的意思是雙引號「查詢」後的單詞' –

回答

0

如果刪除iferror,你會看到錯誤消息:

錯誤

IFS期望所有參數位置0後成對。

我想你想設置默認值,如果公式給出了錯誤值「沒有結果」。如果沒有它,公式將無法正確使用圓括號:

=iferror(
    IFS(B9="Value", 
      "some value", 
     B9 = "value 2", 
      "other query") 
,"NO RESULTS") 
+0

謝謝mark,由於某些原因,當我使用IFS時,只有一行返回,當查詢應該返回100行時。新版本 –