首页 > 解决方案 > 如何使用类似索引匹配的语句来增强我的查询?

问题描述

链接到工作表
上下文:通过 API 调用,我将价格表数据从 Airtable 获取到工作表中。在 Airtable 中,表是链接的,因此我看到的是 Airtable 生成的主键,而不是实际的字段数据。我可以在使用 API 调用创建的单独选项卡中找到数据的表。

挑战:我正在尝试创建一个带有下拉字段的价目表,该字段在选择模型后会生成相关数据。此查询用于:

=UNIQUE(QUERY(models,"SELECT F, E, R, R*(1-0.15), R*0.15, R*1.07 WHERE J = '"&$A$1&"' AND (F = 'rec99pY85FrcpKWmh' OR F ='reccliFdf3cbYeADx') AND F <> '' LABEL R 'Retail excl. VAT', R*(1-0.15) 'Store Price', R*0.15 'Margin', R*1.07 'Retail incl. VAT' FORMAT R '฿ ###,##0', R*(1-0.15) '฿ ###,##0', R*0.15 '฿ ###,##0', R*1.07 '฿ ###,##0' ",1))

我需要用相应的标签替换材料和尺寸下的字符串。我可以用这个公式做到这一点:

=SUBSTITUTE(B3,B3,index(indexBodySizes,match(B3:B13,idSizes,0),6))

对于尺寸和

=SUBSTITUTE(A3,A3,index(indexBodyMaterials,match(A3:A13,idMaterials,0),1))

为材料。

问题:如何将这些单独的子解决方案的功能组合到查询中?

标签: google-sheetsgoogle-sheets-formulaarray-formulasgoogle-sheets-querygs-vlookup

解决方案


=ARRAYFORMULA({UNIQUE(QUERY(models, 
 "select F,E,R,R*(1-0.15),R*0.15,R*1.07 
  where  J = '"&$A$1&"' 
    and (F = 'rec99pY85FrcpKWmh' 
     or  F = 'reccliFdf3cbYeADx') 
    and  F <> '' 
  label  R 'Retail excl. VAT',R*(1-0.15)'Store Price',R*0.15'Margin',R*1.07'Retail incl. VAT' 
  format R '฿ ###,##0',R*(1-0.15) '฿ ###,##0',R*0.15 '฿ ###,##0',R*1.07 '฿ ###,##0'", 1)), 
 {"Sizes"; IFERROR(VLOOKUP(INDEX(UNIQUE(QUERY(models, 
 "select F,E,R,R*(1-0.15),R*0.15,R*1.07 
  where  J = '"&$A$1&"' 
    and (F = 'rec99pY85FrcpKWmh' 
     or  F = 'reccliFdf3cbYeADx') 
    and  F <> '' 
  label  R'',R*(1-0.15)'',R*0.15'',R*1.07''", 0)),,2), Sizes!A:G, 7, 0))},
 {"Materials"; IFERROR(VLOOKUP(INDEX(UNIQUE(QUERY(models, 
 "select F,E,R,R*(1-0.15),R*0.15,R*1.07 
  where  J = '"&$A$1&"' 
    and (F = 'rec99pY85FrcpKWmh' 
     or  F = 'reccliFdf3cbYeADx') 
    and  F <> '' 
  label  R'',R*(1-0.15)'',R*0.15'',R*1.07''", 0)),,1), Materials!A:B, 2, 0))}})

0


=ARRAYFORMULA({{"Material"; IFERROR(VLOOKUP(INDEX(UNIQUE(QUERY(models, 
 "select F,E 
  where  J = '"&$A$1&"' 
    and (F = 'rec99pY85FrcpKWmh' 
     or  F = 'reccliFdf3cbYeADx') 
    and  F <> ''", 0)),,1), Materials!A:B, 2, 0))},
{"Size"; IFERROR(VLOOKUP(INDEX(UNIQUE(QUERY(models, 
 "select F,E
  where  J = '"&$A$1&"' 
    and (F = 'rec99pY85FrcpKWmh' 
     or  F = 'reccliFdf3cbYeADx') 
    and  F <> ''", 0)),,2), Sizes!A:G, 7, 0))},
UNIQUE(QUERY(models, 
 "select R,R*(1-0.15),R*0.15,R*1.07 
  where  J = '"&$A$1&"' 
    and (F = 'rec99pY85FrcpKWmh' 
     or  F = 'reccliFdf3cbYeADx') 
    and  F <> '' 
  label  R 'Retail excl. VAT',R*(1-0.15)'Store Price',R*0.15'Margin',R*1.07'Retail incl. VAT' 
  format R '฿ ###,##0',R*(1-0.15) '฿ ###,##0',R*0.15 '฿ ###,##0',R*1.07 '฿ ###,##0'", 1))})

0


推荐阅读