google-sheets - 如何使用类似索引匹配的语句来增强我的查询?
问题描述
链接到工作表
上下文:通过 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))
为材料。
问题:如何将这些单独的子解决方案的功能组合到查询中?
解决方案
=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))}})
=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))})
推荐阅读
- c - 运行时无法在我的代码中切换开关状态 (ATMEGA328p)
- python - 迁移错误(迁移在其依赖accounts.0001_initial数据库'default'之前应用)
- android - Android 11:启动另一个应用程序的服务
- node.js - 即使返回的数组值正确,Jest 测试也会失败
- java - 如何在服务器端启用 google api
- r - ggplot2轴文字标签:下标+上标+方括号
- visual-studio-code - 使用 Jupyter 在 VScode 中插入新行
- node.js - 无法从回调函数返回正文
- php - Dropdown value does not passing to SQL query (dropdown value came from a table)
- python - 没有名为“ffi”的模块