In Numbers/Excel how can I do a SUMPRODUCT only on rows matching a specific criteria
Let me explain my spreadsheet a little bit. Here is a good screenshot of it:

I have created this spreadsheet essentially because I have gotten tired of the usability issues of just about every nutrition tracking app. So I am creating my own spreadsheet! As you can see going horizontally are different foods/ingredients and below are their nutrition fact values.
Then you will see that towards the bottom there is a row titled "first meal" with some values. This is essentially me saying "2.5 servings of quinoa, 2 servings of lentils" etc. This information is then shown in the table below with "First Meal" in the left.*
My goal now is to allow for two things.
- Multiple meals
- Meals made of other meals
- (Imagine there were rows "Carb Breakfast" "Fat Lunch" Protein Dinner" and those were each meal tables but I wanted a table that combined them that was titled "Carb Breakfast, Fat Lunch, Protein Dinner")
I am having a bit of difficulty doing so and essentially it comes down to the formula for row D on the "first meal" table. The formula for it is currently SUMPRODUCT(Row Fat, Row First Meal) and as you can imagine SUMPRODUCT(Row Cholestrol, Row First Meal). This works alright for one meal but is just a lot of work to tweak for multiple meals and does not work for multiple meals.
The goal would be that the value of each cell in column D be essentially determined by the following formula.
nutrient = // whatever row we are on
integer sum = 0;
foreach(row in top table):
integer weight = [ammount of the 'nutrient' in this row]
integer innersum = 0;
foreach(meal in meals):
if (meal is contained in string top left corner of this table):
innersum += [number of servings of this row];
sum += innersum * weight;
Forgive me, I am a programmer so that is really the most clear way I could explain this formula. Essentially for each food item look at the top left cell in your table and get the sum of the servings for that food item based on that string then multiply that by how much of the correct nutrient is in the meal.
Ideally this formula for the value in cell D would be implemented sort of as follows:
Take the matrix of all of meals from the top table and filter out rows that have names that are not contained in your top left column. Then simplify this matrix into a single row by adding up all the elements in a column. Then do a sumproduct with that value and the number of the specific nutrient from the meals nutrition facts. The problem is I dont know how to do the whole matrix filter and simplify operation. Frankly I dont know if that is even how spreadsheets work.
*Do not fret I designed this meal with a full day of food in mind.
microsoft-excel worksheet-function spreadsheet iwork-numbers
add a comment |
Let me explain my spreadsheet a little bit. Here is a good screenshot of it:

I have created this spreadsheet essentially because I have gotten tired of the usability issues of just about every nutrition tracking app. So I am creating my own spreadsheet! As you can see going horizontally are different foods/ingredients and below are their nutrition fact values.
Then you will see that towards the bottom there is a row titled "first meal" with some values. This is essentially me saying "2.5 servings of quinoa, 2 servings of lentils" etc. This information is then shown in the table below with "First Meal" in the left.*
My goal now is to allow for two things.
- Multiple meals
- Meals made of other meals
- (Imagine there were rows "Carb Breakfast" "Fat Lunch" Protein Dinner" and those were each meal tables but I wanted a table that combined them that was titled "Carb Breakfast, Fat Lunch, Protein Dinner")
I am having a bit of difficulty doing so and essentially it comes down to the formula for row D on the "first meal" table. The formula for it is currently SUMPRODUCT(Row Fat, Row First Meal) and as you can imagine SUMPRODUCT(Row Cholestrol, Row First Meal). This works alright for one meal but is just a lot of work to tweak for multiple meals and does not work for multiple meals.
The goal would be that the value of each cell in column D be essentially determined by the following formula.
nutrient = // whatever row we are on
integer sum = 0;
foreach(row in top table):
integer weight = [ammount of the 'nutrient' in this row]
integer innersum = 0;
foreach(meal in meals):
if (meal is contained in string top left corner of this table):
innersum += [number of servings of this row];
sum += innersum * weight;
Forgive me, I am a programmer so that is really the most clear way I could explain this formula. Essentially for each food item look at the top left cell in your table and get the sum of the servings for that food item based on that string then multiply that by how much of the correct nutrient is in the meal.
Ideally this formula for the value in cell D would be implemented sort of as follows:
Take the matrix of all of meals from the top table and filter out rows that have names that are not contained in your top left column. Then simplify this matrix into a single row by adding up all the elements in a column. Then do a sumproduct with that value and the number of the specific nutrient from the meals nutrition facts. The problem is I dont know how to do the whole matrix filter and simplify operation. Frankly I dont know if that is even how spreadsheets work.
*Do not fret I designed this meal with a full day of food in mind.
microsoft-excel worksheet-function spreadsheet iwork-numbers
Does it need to be a worksheet function thing? Maybe this could be made with VBA.
– Moacir
Jan 14 at 17:20
add a comment |
Let me explain my spreadsheet a little bit. Here is a good screenshot of it:

I have created this spreadsheet essentially because I have gotten tired of the usability issues of just about every nutrition tracking app. So I am creating my own spreadsheet! As you can see going horizontally are different foods/ingredients and below are their nutrition fact values.
Then you will see that towards the bottom there is a row titled "first meal" with some values. This is essentially me saying "2.5 servings of quinoa, 2 servings of lentils" etc. This information is then shown in the table below with "First Meal" in the left.*
My goal now is to allow for two things.
- Multiple meals
- Meals made of other meals
- (Imagine there were rows "Carb Breakfast" "Fat Lunch" Protein Dinner" and those were each meal tables but I wanted a table that combined them that was titled "Carb Breakfast, Fat Lunch, Protein Dinner")
I am having a bit of difficulty doing so and essentially it comes down to the formula for row D on the "first meal" table. The formula for it is currently SUMPRODUCT(Row Fat, Row First Meal) and as you can imagine SUMPRODUCT(Row Cholestrol, Row First Meal). This works alright for one meal but is just a lot of work to tweak for multiple meals and does not work for multiple meals.
The goal would be that the value of each cell in column D be essentially determined by the following formula.
nutrient = // whatever row we are on
integer sum = 0;
foreach(row in top table):
integer weight = [ammount of the 'nutrient' in this row]
integer innersum = 0;
foreach(meal in meals):
if (meal is contained in string top left corner of this table):
innersum += [number of servings of this row];
sum += innersum * weight;
Forgive me, I am a programmer so that is really the most clear way I could explain this formula. Essentially for each food item look at the top left cell in your table and get the sum of the servings for that food item based on that string then multiply that by how much of the correct nutrient is in the meal.
Ideally this formula for the value in cell D would be implemented sort of as follows:
Take the matrix of all of meals from the top table and filter out rows that have names that are not contained in your top left column. Then simplify this matrix into a single row by adding up all the elements in a column. Then do a sumproduct with that value and the number of the specific nutrient from the meals nutrition facts. The problem is I dont know how to do the whole matrix filter and simplify operation. Frankly I dont know if that is even how spreadsheets work.
*Do not fret I designed this meal with a full day of food in mind.
microsoft-excel worksheet-function spreadsheet iwork-numbers
Let me explain my spreadsheet a little bit. Here is a good screenshot of it:

I have created this spreadsheet essentially because I have gotten tired of the usability issues of just about every nutrition tracking app. So I am creating my own spreadsheet! As you can see going horizontally are different foods/ingredients and below are their nutrition fact values.
Then you will see that towards the bottom there is a row titled "first meal" with some values. This is essentially me saying "2.5 servings of quinoa, 2 servings of lentils" etc. This information is then shown in the table below with "First Meal" in the left.*
My goal now is to allow for two things.
- Multiple meals
- Meals made of other meals
- (Imagine there were rows "Carb Breakfast" "Fat Lunch" Protein Dinner" and those were each meal tables but I wanted a table that combined them that was titled "Carb Breakfast, Fat Lunch, Protein Dinner")
I am having a bit of difficulty doing so and essentially it comes down to the formula for row D on the "first meal" table. The formula for it is currently SUMPRODUCT(Row Fat, Row First Meal) and as you can imagine SUMPRODUCT(Row Cholestrol, Row First Meal). This works alright for one meal but is just a lot of work to tweak for multiple meals and does not work for multiple meals.
The goal would be that the value of each cell in column D be essentially determined by the following formula.
nutrient = // whatever row we are on
integer sum = 0;
foreach(row in top table):
integer weight = [ammount of the 'nutrient' in this row]
integer innersum = 0;
foreach(meal in meals):
if (meal is contained in string top left corner of this table):
innersum += [number of servings of this row];
sum += innersum * weight;
Forgive me, I am a programmer so that is really the most clear way I could explain this formula. Essentially for each food item look at the top left cell in your table and get the sum of the servings for that food item based on that string then multiply that by how much of the correct nutrient is in the meal.
Ideally this formula for the value in cell D would be implemented sort of as follows:
Take the matrix of all of meals from the top table and filter out rows that have names that are not contained in your top left column. Then simplify this matrix into a single row by adding up all the elements in a column. Then do a sumproduct with that value and the number of the specific nutrient from the meals nutrition facts. The problem is I dont know how to do the whole matrix filter and simplify operation. Frankly I dont know if that is even how spreadsheets work.
*Do not fret I designed this meal with a full day of food in mind.
microsoft-excel worksheet-function spreadsheet iwork-numbers
microsoft-excel worksheet-function spreadsheet iwork-numbers
asked Jan 13 at 4:38
J.DoeJ.Doe
12615
12615
Does it need to be a worksheet function thing? Maybe this could be made with VBA.
– Moacir
Jan 14 at 17:20
add a comment |
Does it need to be a worksheet function thing? Maybe this could be made with VBA.
– Moacir
Jan 14 at 17:20
Does it need to be a worksheet function thing? Maybe this could be made with VBA.
– Moacir
Jan 14 at 17:20
Does it need to be a worksheet function thing? Maybe this could be made with VBA.
– Moacir
Jan 14 at 17:20
add a comment |
0
active
oldest
votes
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%2f1393680%2fin-numbers-excel-how-can-i-do-a-sumproduct-only-on-rows-matching-a-specific-crit%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
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%2f1393680%2fin-numbers-excel-how-can-i-do-a-sumproduct-only-on-rows-matching-a-specific-crit%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
Does it need to be a worksheet function thing? Maybe this could be made with VBA.
– Moacir
Jan 14 at 17:20