Summing up amounts if one row contains a key within another sheet
I have two sheets in one LibreOffice Calc document:
Sheet1:
| Key | Amount |
|-----|---------|
| ABC | 1 |
| DEF | 2 |
| GHI | 3 |
Sheet2:
| Keys |
|-------|
| ABC |
| XYZ |
| JKL |
| GHI |
Now I'd like to add the amounts in the rows of Sheet1 but only where the key is contained anywhere in Sheet2. For the example above, the sum would be 4
(keys ABC
with amount 1
and GHI
with amount 3
).
I've been solving this with an "Advanced Filter" and SUBTOTAL
but I'd really like a solution where I don't have to re-apply the filter when the sheets change. Any help would be greatly appreciated!
libreoffice-calc
add a comment |
I have two sheets in one LibreOffice Calc document:
Sheet1:
| Key | Amount |
|-----|---------|
| ABC | 1 |
| DEF | 2 |
| GHI | 3 |
Sheet2:
| Keys |
|-------|
| ABC |
| XYZ |
| JKL |
| GHI |
Now I'd like to add the amounts in the rows of Sheet1 but only where the key is contained anywhere in Sheet2. For the example above, the sum would be 4
(keys ABC
with amount 1
and GHI
with amount 3
).
I've been solving this with an "Advanced Filter" and SUBTOTAL
but I'd really like a solution where I don't have to re-apply the filter when the sheets change. Any help would be greatly appreciated!
libreoffice-calc
So the result you're looking for is just the sum? Where does that appear (Sheet1 or Sheet2)?
– fixer1234
Jan 22 at 20:32
add a comment |
I have two sheets in one LibreOffice Calc document:
Sheet1:
| Key | Amount |
|-----|---------|
| ABC | 1 |
| DEF | 2 |
| GHI | 3 |
Sheet2:
| Keys |
|-------|
| ABC |
| XYZ |
| JKL |
| GHI |
Now I'd like to add the amounts in the rows of Sheet1 but only where the key is contained anywhere in Sheet2. For the example above, the sum would be 4
(keys ABC
with amount 1
and GHI
with amount 3
).
I've been solving this with an "Advanced Filter" and SUBTOTAL
but I'd really like a solution where I don't have to re-apply the filter when the sheets change. Any help would be greatly appreciated!
libreoffice-calc
I have two sheets in one LibreOffice Calc document:
Sheet1:
| Key | Amount |
|-----|---------|
| ABC | 1 |
| DEF | 2 |
| GHI | 3 |
Sheet2:
| Keys |
|-------|
| ABC |
| XYZ |
| JKL |
| GHI |
Now I'd like to add the amounts in the rows of Sheet1 but only where the key is contained anywhere in Sheet2. For the example above, the sum would be 4
(keys ABC
with amount 1
and GHI
with amount 3
).
I've been solving this with an "Advanced Filter" and SUBTOTAL
but I'd really like a solution where I don't have to re-apply the filter when the sheets change. Any help would be greatly appreciated!
libreoffice-calc
libreoffice-calc
asked Jan 22 at 12:58
JonasJonas
1032
1032
So the result you're looking for is just the sum? Where does that appear (Sheet1 or Sheet2)?
– fixer1234
Jan 22 at 20:32
add a comment |
So the result you're looking for is just the sum? Where does that appear (Sheet1 or Sheet2)?
– fixer1234
Jan 22 at 20:32
So the result you're looking for is just the sum? Where does that appear (Sheet1 or Sheet2)?
– fixer1234
Jan 22 at 20:32
So the result you're looking for is just the sum? Where does that appear (Sheet1 or Sheet2)?
– fixer1234
Jan 22 at 20:32
add a comment |
1 Answer
1
active
oldest
votes
One approach would be to combine SUMPRODUCT with COUNTIF. I copied your example.
Sheet2:
Sheet1:
The formula in E2:
=SUMPRODUCT(COUNTIF(Sheet2!$A$2:$A$5,"="&$A$2:$A$4)*$B$2:$B$4)
SUMPRODUCT does an array-style calculation on the result of COUNTIF for each row on Sheet1 multiplied by the amount in column B. Assuming the keys on Sheet2 don't contain duplicates, the count will be 1
if Sheet2 contains the key, or 0
if not.
I recommend using explicit ranges rather than simple column references (i.e., A:A). You can pad the explicit ranges with blank rows to allow for any potential expansion you might need, and the formula will still work. However, it takes Calc forever to evaluate entire columns.
Thanks for your solution! It seems very elegant, unfortunately it gives an "Error 508". If I replace the comma with a semicolon, it turns into "#NAME?". I'm on LibreOffice 6, by the way.
– Jonas
Jan 23 at 7:09
@Jonas, did you try it as written first? InTools | Options | LibreOffice Calc | Formula
, what are the separators shown? Where are you located, and what locale and language settings do you use? Error 508 indicates unbalanced parentheses. Double check the formula. FYI: help.libreoffice.org/Calc/Error_Codes_in_Calc
– fixer1234
Jan 23 at 7:18
Thanks for the quick reply! I'm in Germany with a German version of LibreOffice. The separator in the menu you indicated shows ";" so that would explain the difference. The checkbox saying "Use english function names" is checked, however.
– Jonas
Jan 23 at 7:36
@Jonas, the 508 error sounds like maybe a typing mistake in entering the formula. Check the parentheses. Do you have Formula (same path as previous comment) set toExcel A1
? That follows Excel's conventions. The LO default uses some different conventions, including the sheet name separator (I keep mine set to Excel).
– fixer1234
Jan 23 at 7:47
Sorry, my bad! I used the wrong quotes (single instead of double) for the=
. Now it works, thanks a lot!
– Jonas
Jan 23 at 8:46
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1397012%2fsumming-up-amounts-if-one-row-contains-a-key-within-another-sheet%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
One approach would be to combine SUMPRODUCT with COUNTIF. I copied your example.
Sheet2:
Sheet1:
The formula in E2:
=SUMPRODUCT(COUNTIF(Sheet2!$A$2:$A$5,"="&$A$2:$A$4)*$B$2:$B$4)
SUMPRODUCT does an array-style calculation on the result of COUNTIF for each row on Sheet1 multiplied by the amount in column B. Assuming the keys on Sheet2 don't contain duplicates, the count will be 1
if Sheet2 contains the key, or 0
if not.
I recommend using explicit ranges rather than simple column references (i.e., A:A). You can pad the explicit ranges with blank rows to allow for any potential expansion you might need, and the formula will still work. However, it takes Calc forever to evaluate entire columns.
Thanks for your solution! It seems very elegant, unfortunately it gives an "Error 508". If I replace the comma with a semicolon, it turns into "#NAME?". I'm on LibreOffice 6, by the way.
– Jonas
Jan 23 at 7:09
@Jonas, did you try it as written first? InTools | Options | LibreOffice Calc | Formula
, what are the separators shown? Where are you located, and what locale and language settings do you use? Error 508 indicates unbalanced parentheses. Double check the formula. FYI: help.libreoffice.org/Calc/Error_Codes_in_Calc
– fixer1234
Jan 23 at 7:18
Thanks for the quick reply! I'm in Germany with a German version of LibreOffice. The separator in the menu you indicated shows ";" so that would explain the difference. The checkbox saying "Use english function names" is checked, however.
– Jonas
Jan 23 at 7:36
@Jonas, the 508 error sounds like maybe a typing mistake in entering the formula. Check the parentheses. Do you have Formula (same path as previous comment) set toExcel A1
? That follows Excel's conventions. The LO default uses some different conventions, including the sheet name separator (I keep mine set to Excel).
– fixer1234
Jan 23 at 7:47
Sorry, my bad! I used the wrong quotes (single instead of double) for the=
. Now it works, thanks a lot!
– Jonas
Jan 23 at 8:46
add a comment |
One approach would be to combine SUMPRODUCT with COUNTIF. I copied your example.
Sheet2:
Sheet1:
The formula in E2:
=SUMPRODUCT(COUNTIF(Sheet2!$A$2:$A$5,"="&$A$2:$A$4)*$B$2:$B$4)
SUMPRODUCT does an array-style calculation on the result of COUNTIF for each row on Sheet1 multiplied by the amount in column B. Assuming the keys on Sheet2 don't contain duplicates, the count will be 1
if Sheet2 contains the key, or 0
if not.
I recommend using explicit ranges rather than simple column references (i.e., A:A). You can pad the explicit ranges with blank rows to allow for any potential expansion you might need, and the formula will still work. However, it takes Calc forever to evaluate entire columns.
Thanks for your solution! It seems very elegant, unfortunately it gives an "Error 508". If I replace the comma with a semicolon, it turns into "#NAME?". I'm on LibreOffice 6, by the way.
– Jonas
Jan 23 at 7:09
@Jonas, did you try it as written first? InTools | Options | LibreOffice Calc | Formula
, what are the separators shown? Where are you located, and what locale and language settings do you use? Error 508 indicates unbalanced parentheses. Double check the formula. FYI: help.libreoffice.org/Calc/Error_Codes_in_Calc
– fixer1234
Jan 23 at 7:18
Thanks for the quick reply! I'm in Germany with a German version of LibreOffice. The separator in the menu you indicated shows ";" so that would explain the difference. The checkbox saying "Use english function names" is checked, however.
– Jonas
Jan 23 at 7:36
@Jonas, the 508 error sounds like maybe a typing mistake in entering the formula. Check the parentheses. Do you have Formula (same path as previous comment) set toExcel A1
? That follows Excel's conventions. The LO default uses some different conventions, including the sheet name separator (I keep mine set to Excel).
– fixer1234
Jan 23 at 7:47
Sorry, my bad! I used the wrong quotes (single instead of double) for the=
. Now it works, thanks a lot!
– Jonas
Jan 23 at 8:46
add a comment |
One approach would be to combine SUMPRODUCT with COUNTIF. I copied your example.
Sheet2:
Sheet1:
The formula in E2:
=SUMPRODUCT(COUNTIF(Sheet2!$A$2:$A$5,"="&$A$2:$A$4)*$B$2:$B$4)
SUMPRODUCT does an array-style calculation on the result of COUNTIF for each row on Sheet1 multiplied by the amount in column B. Assuming the keys on Sheet2 don't contain duplicates, the count will be 1
if Sheet2 contains the key, or 0
if not.
I recommend using explicit ranges rather than simple column references (i.e., A:A). You can pad the explicit ranges with blank rows to allow for any potential expansion you might need, and the formula will still work. However, it takes Calc forever to evaluate entire columns.
One approach would be to combine SUMPRODUCT with COUNTIF. I copied your example.
Sheet2:
Sheet1:
The formula in E2:
=SUMPRODUCT(COUNTIF(Sheet2!$A$2:$A$5,"="&$A$2:$A$4)*$B$2:$B$4)
SUMPRODUCT does an array-style calculation on the result of COUNTIF for each row on Sheet1 multiplied by the amount in column B. Assuming the keys on Sheet2 don't contain duplicates, the count will be 1
if Sheet2 contains the key, or 0
if not.
I recommend using explicit ranges rather than simple column references (i.e., A:A). You can pad the explicit ranges with blank rows to allow for any potential expansion you might need, and the formula will still work. However, it takes Calc forever to evaluate entire columns.
edited Jan 22 at 21:29
answered Jan 22 at 21:10
fixer1234fixer1234
18.7k144982
18.7k144982
Thanks for your solution! It seems very elegant, unfortunately it gives an "Error 508". If I replace the comma with a semicolon, it turns into "#NAME?". I'm on LibreOffice 6, by the way.
– Jonas
Jan 23 at 7:09
@Jonas, did you try it as written first? InTools | Options | LibreOffice Calc | Formula
, what are the separators shown? Where are you located, and what locale and language settings do you use? Error 508 indicates unbalanced parentheses. Double check the formula. FYI: help.libreoffice.org/Calc/Error_Codes_in_Calc
– fixer1234
Jan 23 at 7:18
Thanks for the quick reply! I'm in Germany with a German version of LibreOffice. The separator in the menu you indicated shows ";" so that would explain the difference. The checkbox saying "Use english function names" is checked, however.
– Jonas
Jan 23 at 7:36
@Jonas, the 508 error sounds like maybe a typing mistake in entering the formula. Check the parentheses. Do you have Formula (same path as previous comment) set toExcel A1
? That follows Excel's conventions. The LO default uses some different conventions, including the sheet name separator (I keep mine set to Excel).
– fixer1234
Jan 23 at 7:47
Sorry, my bad! I used the wrong quotes (single instead of double) for the=
. Now it works, thanks a lot!
– Jonas
Jan 23 at 8:46
add a comment |
Thanks for your solution! It seems very elegant, unfortunately it gives an "Error 508". If I replace the comma with a semicolon, it turns into "#NAME?". I'm on LibreOffice 6, by the way.
– Jonas
Jan 23 at 7:09
@Jonas, did you try it as written first? InTools | Options | LibreOffice Calc | Formula
, what are the separators shown? Where are you located, and what locale and language settings do you use? Error 508 indicates unbalanced parentheses. Double check the formula. FYI: help.libreoffice.org/Calc/Error_Codes_in_Calc
– fixer1234
Jan 23 at 7:18
Thanks for the quick reply! I'm in Germany with a German version of LibreOffice. The separator in the menu you indicated shows ";" so that would explain the difference. The checkbox saying "Use english function names" is checked, however.
– Jonas
Jan 23 at 7:36
@Jonas, the 508 error sounds like maybe a typing mistake in entering the formula. Check the parentheses. Do you have Formula (same path as previous comment) set toExcel A1
? That follows Excel's conventions. The LO default uses some different conventions, including the sheet name separator (I keep mine set to Excel).
– fixer1234
Jan 23 at 7:47
Sorry, my bad! I used the wrong quotes (single instead of double) for the=
. Now it works, thanks a lot!
– Jonas
Jan 23 at 8:46
Thanks for your solution! It seems very elegant, unfortunately it gives an "Error 508". If I replace the comma with a semicolon, it turns into "#NAME?". I'm on LibreOffice 6, by the way.
– Jonas
Jan 23 at 7:09
Thanks for your solution! It seems very elegant, unfortunately it gives an "Error 508". If I replace the comma with a semicolon, it turns into "#NAME?". I'm on LibreOffice 6, by the way.
– Jonas
Jan 23 at 7:09
@Jonas, did you try it as written first? In
Tools | Options | LibreOffice Calc | Formula
, what are the separators shown? Where are you located, and what locale and language settings do you use? Error 508 indicates unbalanced parentheses. Double check the formula. FYI: help.libreoffice.org/Calc/Error_Codes_in_Calc– fixer1234
Jan 23 at 7:18
@Jonas, did you try it as written first? In
Tools | Options | LibreOffice Calc | Formula
, what are the separators shown? Where are you located, and what locale and language settings do you use? Error 508 indicates unbalanced parentheses. Double check the formula. FYI: help.libreoffice.org/Calc/Error_Codes_in_Calc– fixer1234
Jan 23 at 7:18
Thanks for the quick reply! I'm in Germany with a German version of LibreOffice. The separator in the menu you indicated shows ";" so that would explain the difference. The checkbox saying "Use english function names" is checked, however.
– Jonas
Jan 23 at 7:36
Thanks for the quick reply! I'm in Germany with a German version of LibreOffice. The separator in the menu you indicated shows ";" so that would explain the difference. The checkbox saying "Use english function names" is checked, however.
– Jonas
Jan 23 at 7:36
@Jonas, the 508 error sounds like maybe a typing mistake in entering the formula. Check the parentheses. Do you have Formula (same path as previous comment) set to
Excel A1
? That follows Excel's conventions. The LO default uses some different conventions, including the sheet name separator (I keep mine set to Excel).– fixer1234
Jan 23 at 7:47
@Jonas, the 508 error sounds like maybe a typing mistake in entering the formula. Check the parentheses. Do you have Formula (same path as previous comment) set to
Excel A1
? That follows Excel's conventions. The LO default uses some different conventions, including the sheet name separator (I keep mine set to Excel).– fixer1234
Jan 23 at 7:47
Sorry, my bad! I used the wrong quotes (single instead of double) for the
=
. Now it works, thanks a lot!– Jonas
Jan 23 at 8:46
Sorry, my bad! I used the wrong quotes (single instead of double) for the
=
. Now it works, thanks a lot!– Jonas
Jan 23 at 8:46
add a comment |
Thanks for contributing an answer to Super User!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1397012%2fsumming-up-amounts-if-one-row-contains-a-key-within-another-sheet%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
So the result you're looking for is just the sum? Where does that appear (Sheet1 or Sheet2)?
– fixer1234
Jan 22 at 20:32