简体   繁体   English

Google 表格 - 在查询中使用 IF 语句

[英]Google Sheets - Using an IF statement in a Query

I am making a spreadsheet for taxes on my crypto purchases and sales.我正在为我的加密货币购买和销售制作一个电子表格。 I have the QUERY function to pull the data from my main sheet to my TAX sheet but I need my amount of coins to show up negative on a sale.我有查询 function 将数据从我的主表拉到我的税表,但我需要我的硬币数量在销售中显示为负数。 I want to make a number negative if "sell" is present or keep it positive if "buy".如果存在“卖出”,我想将一个数字设为负数,如果“买入”,我想将其设为正数。 I am trying to use an IF statement inside a QUERY.我正在尝试在 QUERY 中使用 IF 语句。

=QUERY(Trading:$A$3,H1001, "select A,B,C,D,E,GH where B contains 'Crypto:com'" & if(Trading,F:F = "SELL", Trading!D:D -1, Trading:D:D 1)) =QUERY(Trading:$A$3,H1001, "选择 A,B,C,D,E,GH 其中 B 包含 'Crypto:com'" & if(Trading,F:F = "SELL", Trading!D: D -1,交易:D:D 1))

Link to Sample sheet 链接到样品表

The locked pages are editable but are just used to gather or receive data from the Trading page.锁定页面是可编辑的,但仅用于从交易页面收集或接收数据。

We can only basically guess without access to see your actual sheets, data and layout (screenshots don't help much).我们基本上只能猜测而无法查看您的实际工作表、数据和布局(屏幕截图没有多大帮助)。 That said, conceptually, this should work:也就是说,从概念上讲,这应该有效:

=ArrayFormula(IFERROR(FILTER({Trading:A3,C:UPPER(Trading,D3:D)*-1,Trading:E3,E:Trading,G3,H}: UPPER(Trading!F3:F)="SELL", ISNUMBER(SEARCH("Crypto",Trading!B3:B)))))

If that does not work, I recommend sharing a link to a sample document, being sure to set the link's Share permissions (when you create the link) to "Anyone with the link..." and "Editor."如果这不起作用,我建议共享指向示例文档的链接,确保将链接的共享权限(当您创建链接时)设置为“知道链接的任何人...”和“编辑者”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM