Excel - 基于另一列值的总和

时间:2018-04-29 21:19:15

标签: excel excel-formula google-sheets

我知道这是我需要使用的某种嵌套方程式,但我无法理清逻辑。另外,我知道它的标题是Excel,但它实际上是Google表格,我想这不应该那么重要。

我的表格如下,我正在尝试自动计算[差异]:

Name        Action        Buy Value        Sell Value        Difference
-----------------------------------------------------------------------
John        BUY           $100             --                --
John        BUY           $50              --                --
John        SELL          --               $200              $50
Sam         BUY           $25              --                -- 
Sam         BUY           $50              --                --
Sam         BUY           $50              --                --
Sam         SELL          --               $100              -$25

如果[行动]是“卖出”,如果[行动]为“买入”且[名称]与“卖出”[行动]相匹配,我需要将[买入值]相加。

2 个答案:

答案 0 :(得分:0)

我会为每个人创建一个小计行,其中包含该行总和的买入价值,卖出价值和差值。

Name        Action        Buy Value        Sell Value        Difference
-----------------------------------------------------------------------
John        BUY           $100             --                --
John        BUY           $50              --                --
John        SELL          --               $200              --
John        SUBTOTAL      $150 (sum)       $200 (sum)        $50 (Sell - Buy)
Sam         BUY           $25              --                -- 
Sam         BUY           $50              --                --
Sam         BUY           $50              --                --
Sam         SELL          --               $100              --
Sam         SUBTOTAL      $125 (sum)       $100 (sum)        -$25 (Sell - Buy)

答案 1 :(得分:0)

我发表了关于使用Google表格QUERY功能的评论,但如果您的名字在左侧重复出现并且看起来您想要数据在您的示例中,但是自动化,那么这可能无效...

Example

这适用于Excel,但这里是复制Sheets版本的链接。 https://docs.google.com/spreadsheets/d/1EejBcZ2IdAQArbZv-dlq5obbA4OlD56zkvIhoZWQjKM/copy?usp=sharing

正如您在我的示例中所看到的,G列中有一个辅助公式

{ "name": "com.bg.lter", "displayName": "LTER", "version": "1.0.0", "description": "A sample Apache Cordova application that responds to the deviceready event.", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "Apache Cordova Team", "license": "Apache-2.0", "dependencies": { "cordova-android": "^7.0.0", "cordova-browser": "^5.0.3", "cordova-ios": "^4.5.4", "cordova-plugin-add-swift-support": "^1.7.2", "cordova-plugin-file": "^6.0.1", "cordova-plugin-network-information": "^2.0.1", "cordova-plugin-websocket-server": "^1.4.10", "cordova-plugin-whitelist": "^1.3.3", "express": "^4.15.2", "jquery": "^3.3.1", "socket.io": "^2.1.0", "socket.io-client": "^2.1.0", "socket.io-parser": "^3.2.0" }, "cordova": { "plugins": { "cordova-plugin-whitelist": {}, "cordova-plugin-network-information": {}, "cordova-plugin-websocket-server": {}, "cordova-plugin-file": {} }, "platforms": [ "ios", "android", "browser" ] }

公式使用单元格地址填充列G,其中名称列更改为新名称。 F列中的公式可以使用G列中的值和INDIRECT来创建BUY值的总和范围。

=IF(B5<>B4,"D"&ROW(),G4)

这会自动化差异列中的值,前提是数据已按照示例中的说明进行了扩展。我已经读过在大量单元格中使用INDIRECT可能会非常费力并且可能会影响性能。

相关问题