How to sum same fields quantity in a repeating group list?

Hello :slight_smile:

I’m very a new user on bubble (i started 1 week ago)
I’m trying to create a simple shooping list app for personnal use. I’m thanking by advance more experienced user who can give me some tips :blush:

Principle:
In a dropdown menu, i choose the list of recipe for the next week.
In my database “Recette” i have previously provided:

  • the recipe name
  • Ingredients related to this recipe (text type)
  • Quantity for each ingredient of this recipe (number type)

My issue is the following:
All ingredients and quantities are displayed just fine but i cannot figure out how to ask to bubble to show only one time an ingredient that is used for multiple recipe and then sum the related quantity for these ingredient that are used multiple times.

Concrete exemple:
In the picture below, i have selected two recipes.
The ingredient “Tomate” with quantity 1 and “Avocat” with quantity 1 appear 2 times because it is needed for both recipes. To make it perfect, i want that these ingredients appear only 1 time in my repeting group and that the quantity switch to 2

Before
Tomate 1
Avocat 1
Tomate 1
Avocat 1

After
Avocat 2
Tomate 2

1 Like

you are using a repeating group right?

as the datasource use “Do a search for X: grouped by” and then group by ingredient and add aggregation: sum

Hello TipLister,

First, thank you for your reply.

Your idea seems to be a potential solution to my issue, unfortunately, i’m not sure in what repeating group i am supposed to proceed this instruction :frowning:

Another issue is that i dont have just 1 field “Ingrédient” but 7 for 7 potential ingredient by recipe. As a result, when you suggest to “group by ingredient”, I don’t know how to put that in practice. Am i supposed to do it for each one of the 7 ingredients? :confused:

As the issue is complicated, i add some more picture to explain :slight_smile:

Databases
I have Two databases.

  1. Recette:
    When i create a new entry i can fill at max 7 ingredients, 7 related quantities, A recipe Name and image
  2. Shopping List
    This database is just used to store in the field “food” the ingredients related to the recipe selected by the user.

Repeating Groups
I have 2 mains repeating groups:
-Repeating group “Recette”
The first one is used to allow the user to select the recipe for the week. I have first create a repeating group to do a search in the database “Recette” and then another one to retrieve the recipe name in my current cell

-Repeating group “My Shopping List”
This repeating group is used to display ingredients and quantity related to the recipe selected by the user in the dropdown menu.

First, I created a repeating group to do a search in my database “My Shopping List”

Second, I created a new repeating group inside the previous one to display the current cell of “My shooping List”

Third, i created another repeating group to get the parent group’s of My shopping List

Finally, i created a Text Box to display the ingredient 1 retrieved from the database “Recette”. And that for each ingredient and quantity (this is why there are 7 lines)

Is that a probleme that there are 7 fields for each ingredient and quantity?
Where should I put the instruction “Grouped by” and on which ingredient (all of them, on a group?).

Hopefully, someone has an idea to fix this problem :slight_smile:
Thanks for people taking time to help

Best regards

Hi Ines,
I recommend you watch several videos about databases as your setup is not the best.

then

Hello,

I have watched carefully the two videos above and try to work some more to finally fix my issues.

I have totally changed my database as my setup was not optimized at all.
Following the video advice, i have created a database with the list of all my ingredient that will be used to add in a recipe.

In another database called “Recipe” i have provided the repice name, image and created a LIST of ingredients. In that list i copied and pasted the unique number ID of the ingredient created previously in my first database (to reuse).

When i click the button, i want that the list of ingredients of the recipes selected by the user are displayed in a RepeatingGroup.
To do so, in the button workflow i have created a new thing with a type “Liste of course” witch is another database to store the result of the list generated from the user choice. Then i have requested to “add list” in “my current page=index” with a custom state named “user-list” in my field “Weeklylist2”. Then i have created a new state for the user-list.
image

Now, i have my list of list of ingredient displayed but with the unique ID instead of the name and in row instead of column. What i am doing wrong? :disappointed_relieved: I have tried multiple time to pass this step but i am blocked. Can someone explain me how to proceed please :pray:?

Thank you by advance
Best regards

You want user to save recipes and then select one recipe and change ingredients or amount of ingredients right?

can you please show me a screenshot of the datatype liste course what fields it is (if you go to data then liste course)

and also what is repeating group that you have that is not working and showing unique ID instead of name, to show the datasource and content of it and the text inside?

Hello TipLister,

You want user to save recipes and then select one recipe and change ingredients or amount of ingredients right?

Not really… I create in advance recipe with the ingredients included.
In a dropdown list i let the user choose from the list of recipe available what recipes he wants to cook this week. Basically, when the user will select the button “Generate” I want that the list of ingredients linked to the recipes choosen by the user are displayed. In that way, the user knows what ingredients he will need to buy.
For now, i don’t need the user to do anything except click “Generate” and see the correct information :slight_smile:
Next step will be to display also the related quantity of each ingredient and order them by name. But let’s keep simple for now as i’m struggling! :sweat_smile:

My database “Liste course” is the following.
There is only one field “Weekly list2” with the data type “List of recipes”
image

For the repeatingGroup
I have, this repeating group

Inside it, a group with

Inside it, a text box with

Thank you very much for your help :slight_smile:

Best regards

each recipe already has ingredients right?

you can have a repeating group inside a repeating group.

first repeating group can be "current users list of recipes, a field called “list of recipes” that is part of user.

when a user sees a recipe in a repeating group of all recipes and clicks save you do “make changes to current user” list of recipes add: current cells recipe

inside repeating group put another repeating group type ingredients that is called "current cells list of ingredients.

the datatype list course is ONLY needed if you want to make changes to the recipe ingredients that are unique for one user. eg 1 user needs much more ingredients as (s)he is cooking for 5 people.

to do this, in the repeating group ingredients you can have a button “add to recipe”:
This creates a new “list course”. a list course can have the fields "ingredient selected "(type ingredient), recipe (type recipe) and quantity (type number).
Then you have a repeating group searching all list courses created by = current user. with recipe of dropdown selection (dropdown shows current users list of recipes)

If you are really lazy and dont want to change anything, inside your text element “parent groups liste courses weekly lists liste des ingredients” change it to “parent groups list courses weekly lists liste des ingredients “Ingredients”” to show the text instead of unique id should also work.

Hello again :slight_smile:

Okay, i didn’t have the possibility to add “ingredients” at the end of my initial data input “parent groups list courses weekly lists liste des ingredients" but i’ve change it to “current cell’s text” and it work fine! thank you ! :champagne: :tada:

Last step is to delete dupplicate datas (aggregate) while sum the quantity of each same ingredient.
So, here i want to display only one time “Tomato” with quantity switching from 2 to 5 (Qt_1=3+Qt_2=2 => Qt total=5)

(The field quantity is datatype number and a field of “Recipe” database)

From what i understand, i need to use the function “Group by” and then indicate that i want to group by “List of ingredients” and then sum the quantity but i don’t succed to put that in practice.

Thank you by advance
Best regards

Inès

in your repeating group list course where it says “do a search for list courses”
click at the end of that and select :grouped by
then click add new grouping: ingredient
and select sum at the bottom underneath add aggregation.

if this doesnt work it has to do with the fact that you need to change datatypes and fields
eg if I have datatype users who have a field called sport (football, rugby, tennis) only then I can use do a search for users grouped by sport.

Thank you very much TipLister !
It took me some time, but it works well now :blush:

glad I could help Ines!

This topic was automatically closed after 70 days. New replies are no longer allowed.